简体   繁体   中英

libGDX - How to speed up scenario?

I'm developing an Android game, using libGDX in eclipse. I want to speed up my scenario (a treadmill) every time a player scores 10 points. The treadmill has an initial speed equals to 0, and recieves 5 for each 10 points. When the character fall out the screen, the player lose the game. Anyone knows how to do that?

I suppose you realize the treadmill animation with Animation . First take a look at this tutorial . You will note the float stateTime and the first parameter in new Animation(0.025f, walkFrames); . The stateTime describes your current time. This first parameter of Animation describes the duration of a frame. If stateTime is bigger then frameDuration the next Texture / Sprite of the Animation will be drawn. You cannot change this float frameDuration , you can only set it in the constructor. But you can set the stateTime . Normaly you use stateTime += delta , so you have the exact time. To speed it up/ slow it down you can multiply it with float speed :

stateTime += delta * speed;
  1. For speed < 0 a frame would take longer, so the Animation is slower.
  2. For speed == 0 the Animation has its normal speed.
  3. For speed > 0 the Animation is faster.

If you die, just reset the speed to 0, so the treadmill won't be animated, as statetime never gets changed: stateTime + (delta * 0) = stateTime

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM