您好我正在尝试在我的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
}
答案 0 :(得分:1)
您可以测量游戏暂停的时间,并在取消暂停游戏时将其添加到TimePassed。然后TimePassed + 5秒应小于TimeUtils.millis()。
答案 1 :(得分:1)
在某处声明你的_time浮点值。
float _time=0f;
在更新或渲染方法中添加增量时间(自上次更新以来经过的时间量)
_time+=Gdx.graphics.getDeltaTime();
现在检查_time是否大于5
if(_time>5)
{
// do your stuff & reset the timer
_time=0;
}