在尝试计算接触点(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();
}
}
}
}
我收到第一个代码块中指定的错误。
谢谢!