您好,我正在尝试在我的 libgdx 游戏中实现暂停功能,但我无法暂停每 5 秒发生一次的动画。在我的渲染方法中,我每 5 秒重新启动一次动画。动画完成后我停止绘制它并且它们按预期工作重新启动并每 5 秒绘制一次。但是,当我按下暂停按钮时,当前动画结束,这没问题,但一旦我取消暂停游戏,它就会立即重新绘制另一个动画,而不是等到下一个 5 秒时间段。我认为这是因为一旦我取消暂停,TimeUtils.millis() 仍然大于 5 秒,导致它立即再次触发,所以我将如何重置时间以防止这种情况发生。谢谢。
if(TimeUtils.millis()>=(TimePassed+timekeep.timecheck)&& paused==false)
{ //every N seconds and if not paused
System.out.println("Rendering.....");
stateTime =0; //reset animation
for(int i=0;i<=timekeep.rndy-1;i++){
c.e.get(i).alive=true; //set all characters to alive to be drawn
}
TimePassed = TimeUtils.millis(); //this is the time passed since last restart
}
最佳答案
您可以测量游戏暂停的时间,并在您取消暂停游戏时将其添加到 TimePassed。那么 TimePassed + 5 sec 应该小于 TimeUtils.millis()。
关于java - 暂停和恢复每 n 秒发生一次的 SpriteBatch 动画的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23545317/