我试图在屏幕上直线移动一个精灵,朝着我触摸屏幕的位置,我做的是在每个循环中更新(),它检查当前精灵的位置xy = =到目的地x,y.如果它没有精灵的x和y ……
事情是..它不是直线移动…因为有些情况下x或y坐标首先到达目的地x或y …我如何改变它以便x和y都相遇目的地在一起?
我目前的精灵对象的伪代码
destX = destination X
destY = destination Y
posX = current X
posY = current Y
public void update(){
if(destX > posX && destY < posY)
{
posX++;
posY--;
}
else if (destX > posX && destY > posY){
posX++;
posY++;
}
else if(destX < posX && destY > posY)
{
posX--;
posY++;
}
else if(destX < posX && destY < posY){
posX--;
posY--;
}
else if(destX < posX)
posX--;
else if(destX > posX)
posX++;
else if(destY < posY)
posY--;
else if(destY > posY)
posY++;