Vinicius Seganfredo
Vinicius Seganfredo

Reputation: 1764

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?

Upvotes: 0

Views: 401

Answers (1)

Robert P
Robert P

Reputation: 9793

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

Upvotes: 1

Related Questions