タッチ ポイント (dx、dy) 間の関数を計算しようとすると、計算関数を呼び出すときにエラーが発生します。
ここに私の移動機能があります:
public class Mice {
public Movement getRatio;
public static float MX;
public static float MY;
public Mice(float x, float y){
MX = x;
MY = y;
}
public void move(float dx, float dy){
float[] ratio = new float[2];
//below this comment is my error:
ratio = getRatio.getPath(dx, dy, MX, MY);
MX++;
MY = MY + ratio[1];
GameActivity.mpx = MX;
GameActivity.mpy = MY;
}
}
(MX, MY) は、オブジェクトが現在画面上にある別のポイントです。
これが私の計算関数です:
public class Movement {
public float[] getPath(float dx, float dy, float mX, float mY){
float[] ratio = new float[2];
ratio[0] = 1;
float a;
float Ry1;
float Ry2;
float Rx1 = 1;
float Rx2 = 2;
a = (dy-mY)/(dx-mX);
Ry1=a*(Rx1-dx)+dy;
Ry2=a*(Rx2-dx)+dy;
ratio[1] = Math.abs(Ry1-Ry2);
return ratio;
}
}
私の onTouchEvent
@Override
public boolean onTouchEvent(MotionEvent event){
dx = event.getX();
dy = event.getY();
if(event.getAction()==1){
thread = new MiceThread(mice, mview, dx, dy);
thread.start();
}
return true;
}
そして、ここに私のスレッドがあります:
public class MiceThread extends Thread {
private Mice gameMice;
private MiceView gameView;
private float x;
private float y;
public MiceThread(Mice theMice, MiceView theView, float x, float y){
this.gameMice = theMice;
this.gameView = theView;
this.x = x;
this.y = y;
}
public void run(){
while(1<2){
this.gameMice.move(x, y);
this.gameView.postInvalidate();
try
{
MiceThread.sleep(5);
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
コードの最初のブロックで指定された場所でエラーが発生しています。
ありがとう!