[英]libGDX - How to speed up scenario?
I'm developing an Android game, using libGDX in eclipse. 我正在开发一个Android游戏,在eclipse中使用libGDX。 I want to speed up my scenario (a treadmill) every time a player scores 10 points. 每当球员得分达到10分时,我都想加快步伐(跑步机)。 The treadmill has an initial speed equals to 0, and recieves 5 for each 10 points. 跑步机的初始速度等于0,每10点获得5。 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
. 我想您可以通过Animation
实现treadmill
动画。 First take a look at this tutorial . 首先看一下本教程 。 You will note the float stateTime
and the first parameter in new Animation(0.025f, walkFrames);
您将注意到float stateTime
和new Animation(0.025f, walkFrames);
的第一个参数new Animation(0.025f, walkFrames);
. 。 The stateTime
describes your current time. stateTime
描述您的当前时间。 This first parameter of Animation
describes the duration of a frame. Animation
第一个参数描述一帧的持续时间。 If stateTime
is bigger then frameDuration
the next Texture
/ Sprite
of the Animation
will be drawn. 如果stateTime
较大,则frameDuration
将绘制Animation
的下一个Texture
/ Sprite
。 You cannot change this float frameDuration
, you can only set it in the constructor. 您不能更改此float frameDuration
,只能在构造函数中进行设置。 But you can set the stateTime
. 但是您可以设置stateTime
。 Normaly you use stateTime += delta
, so you have the exact time. stateTime += delta
,您使用stateTime += delta
,因此您拥有准确的时间。 To speed it up/ slow it down you can multiply it with float speed
: 要加快/降低速度,您可以将其乘以float speed
:
stateTime += delta * speed;
speed < 0
a frame would take longer, so the Animation
is slower. 对于speed < 0
一帧将花费更长的时间,因此Animation
会更慢。 speed == 0
the Animation
has its normal speed. 对于speed == 0
, Animation
具有其正常速度。 speed > 0
the Animation
is faster. 对于speed > 0
, Animation
会更快。 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
如果死了,只需将speed
重置为0,就不会对treadmill
进行动画处理,因为statetime永远不会改变: stateTime + (delta * 0) = stateTime
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.