计算运动的延续

时间:2014-03-08 00:47:46

标签: java android eclipse libgdx

我有一个使用设备accelerometer控制的精灵。

我的代码是这样的:

// for rotation
double myRadians = Math.atan2(previousRoll, previousPitch);
float myDegress = Math.round(((myRadians*180)/Math.PI));
// set rotation of sprite   
sprite.setRotation(myDegress+90);

// for movement
float yChange = Math.round(previousRoll);
float xChange = Math.round(previousPitch);
float yMove = Math.round(yChange/1.5);
float xMove = Math.round(xChange/1.5);
// set the position of the sprite
sprite.setPosition(sprite.getX()+xMove, sprite.getY()+yMove); 

哪种方法效果很好。

当用户按下后退键时,游戏暂停,显然,停止精灵移动。但是说如果精灵即将碰撞,用户只能暂停,然后向相反方向倾斜设备瞧!他们离开了!

我所拥有的只是速度,由设备的倾斜度定义,我会在暂停事件发生之前存储倾斜度,并在游戏恢复时将其用于移动。

那么,我将如何防止上述情况? 我想我可以将精灵移动到最终位置,如果游戏没有暂停,它将会结束。

如果我有速度,我如何计算从当前位置到结束位置的距离。我知道distance = speed * time,那么有没有办法在这种情况下获得time?还是有另一种方法吗?我对物理学并不太好,因为你可能已经想到了=]]

无论如何,提前谢谢。

1 个答案:

答案 0 :(得分:0)

最后,我解决了我的问题,我所做的是找到了基于distance = speed * time的最终位置。 所以,现在我的精灵转到了“最终位置”。

感谢您的帮助。