我有5帧动画。我想在每个动画周期结束时暂停x秒
1,2,3,4,5(暂停)1,2,3,4,5(暂停)......
Array<AtlasRegion> regions = atlas.findRegions("coin");
animGoldCoin = new Animation(1.0f / 20.0f, regions, PlayMode.LOOP);
我找不到办法。
谢谢
答案 0 :(得分:0)
我不喜欢动画类,你可以自己制作。
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;
}
}
}
我认为这会奏效,你明白我做了什么吗?
答案 1 :(得分:0)
我遇到了类似的问题,但设法提出了解决方案。它适用于我,但可能不是最好的方法..我还在学习。
我从旧动画的帧中创建了一个新动画,但速度为0.它在帧上停止,直到玩家速度发生变化。
if(speedX == 0f && speedY == 0f){
playerIdle = new Animation(0f,playerAnim.getKeyFrames());
playerAnim = playerIdle;
}
我知道这是一个老问题,但希望这对某人有用。
答案 2 :(得分:0)
我在搜索中快速解决了暂停Libgdx动画的问题。 当我按下空格键时,我希望动画暂停。 我确实尝试了上面实例化一个新对象的方法,但确实有效。所以我试着将帧持续时间设置为0,但由于某种原因这不起作用。这是一种不太昂贵的实例化方法。 如果要暂停动画,只需创建三个变量,其中两个是名为toStop的布尔变量,另一个是另一个名为launchFrame的TextureRegion。 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);
}