質問

Hi I am trying to implement a pause feature in my libgdx game but am having trouble pausing the animations that happen every 5 seconds. In my render method I restart the animations every 5 seconds. Once the animation is finished I stop drawing it and they work as expected restarting and drawing every 5 seconds. However when I hit the pause button the current animation finishes off which is ok but as soon as I unpause the game it would immediately redraw another animation rather than waiting until the next 5 second time slot. I think this is because TimeUtils.millis() is still greater than 5 seconds as soon as I unpause causing it to immediately fire again so how would I reset the timming to prevent this. Thanks.

 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

    }
役に立ちましたか?

解決

You can measure the time the game is paused and add it to TimePassed when you unpause the game. Then TimePassed + 5 sec should be smaller then TimeUtils.millis().

他のヒント

Declare your _time float value somewhere up.

float _time=0f;

And in the update or render method add to it the delta time (the ammount of time that passed since the last update)

_time+=Gdx.graphics.getDeltaTime();

Now check if the _time is greater than 5

 if(_time>5)
{
  // do your stuff & reset the timer
 _time=0;


}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top