计算运动的延续



我有一个使用设备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?还是还有另一种方法?我对物理学不太好,因为您可能已经发现=]

无论如何,谢谢。

最后,我解决了我的问题,我所做的是基于distance = speed * time的最终位置。因此,现在我的精灵移至"最终位置"。

感谢您的帮助。

最新更新