Libgdx:在一个动画周期之间暂停
我有5帧的动画。我想在每次动画循环结束时暂停x秒 1,2,3,4,5(暂停)1,2,3,4,5(暂停)Libgdx:在一个动画周期之间暂停,libgdx,Libgdx,我有5帧的动画。我想在每次动画循环结束时暂停x秒 1,2,3,4,5(暂停)1,2,3,4,5(暂停) Array regions=atlas.findRegions(“硬币”); animGoldCoin=新动画(1.0f/20.0f,区域,播放模式.LOOP); 我找不到这样做的方法 谢谢我不太喜欢动画课,你可以自己制作 float pauseTime=5f; // lets say that you want to pause your animation for x secon
Array regions=atlas.findRegions(“硬币”);
animGoldCoin=新动画(1.0f/20.0f,区域,播放模式.LOOP);
我找不到这样做的方法
谢谢我不太喜欢动画课,你可以自己制作
float pauseTime=5f; // lets say that you want to pause your animation for x seconds after each cicle
float stateTime=0f; // this variable will keep the time, is our timer
float frameTime=1/20f; //amount of time from frame to frame
int frame=0; // your frame index
boolean waiting=false; // where this is true, you wait for that x seconds to pass
void Update()
{
stateTime+=Gdx.graphics.getDeltaTime();
if(!waiting && stateTime>frameTime) // that frame time passed
{
stateTime=0f; // reset our 'timer'
frame++; // increment the frame
}
if(waiting && stateTime>=0)
{
frame=0;
waiting=false;
}
if(frame>=NUMBER_OF_FRAMES)
{
frame--;
waiting=true;
stateTime=-pauseTime;
}
}
}
我想这会管用的,你明白我做了什么吗?我刚刚遇到了一个类似的问题,但设法找到了解决办法。这对我来说很有效,但可能不是最好的解决办法。。我还在学习 我从旧动画的帧创建了一个新动画,但速度为0。它停止在帧上,直到播放器速度改变
if(speedX == 0f && speedY == 0f){
playerIdle = new Animation(0f,playerAnim.getKeyFrames());
playerAnim = playerIdle;
}
我知道这是一个老问题,但希望这对某人有用。我在搜索中快速解决了暂停Libgdx动画的问题。 当我按下空格键时,我希望动画暂停。 我确实尝试了上面实例化一个新对象的方法,它确实起了作用。因此,我尝试将帧持续时间设置为0,但由于某些原因,这不起作用。这是一种不需要实例化的成本较低的方法。 如果要暂停动画,只需创建三个变量,其中两个是名为toStop的布尔变量,另一个是名为launchFrame的纹理区域。Haslaunched用于告诉我何时按下空格键
if (InputHandler.hasLaunched && toStop ) {
launchFrame = launchBarAnimation.getKeyFrame(runTime);
toStop = false;
} else if (InputHandler.hasLaunched && !toStop){
batcher.draw(launchFrame, 90, 20, 50, 37);
} else {
batcher.draw(launchBarAnimation.getKeyFrame(runTime), 90, 20, 50, 37);
}
if (InputHandler.hasLaunched && toStop ) {
launchFrame = launchBarAnimation.getKeyFrame(runTime);
toStop = false;
} else if (InputHandler.hasLaunched && !toStop){
batcher.draw(launchFrame, 90, 20, 50, 37);
} else {
batcher.draw(launchBarAnimation.getKeyFrame(runTime), 90, 20, 50, 37);
}