我一直有这个问题已经有一段时间了,我找不到解决方法如何修复它。
我的游戏中有一个角色动画,它的效果非常好,除了这样一个事实:当我退出应用程序并将其输回而不关闭它时,它就会消失。通过“消失”,我并不是说它只是看不见,因为如果是,碰撞检测仍然适用,但事实并非如此。
我正在使用一个自定义动画类,如下所示:
public class Animation {
private Array<TextureRegion> frames;
private float maxFrameTime;
private float currentFrameTime;
private int frameCount;
private int frame;
public Animation(TextureRegion region, int frameCount, float cycleTime){
frames = new Array<TextureRegion>();
int frameWidth = region.getRegionWidth() / frameCount;
for(int i=0; i<=frameCount; i++)
frames.add(new TextureRegion(region, i * frameWidth, 0, frameWidth, region.getRegionHeight()));
this.frameCount = frameCount;
maxFrameTime = cycleTime / frameCount;
frame = 0;
}
public void update(float dt){
currentFrameTime +=dt;
if(currentFrameTime > maxFrameTime) {
frame++;
currentFrameTime = 0;
}
if(frame >= frameCount)
frame = 0;
}
public TextureRegion getFrame(){
return frames.get(frame);
}
}
我听说过一个名为“onPause”的函数,但我不知道如何访问它。即使我可以,我会在那里写什么来解决我的问题?我没有使用GDX的“屏幕”,而是使用定制的“状态”类。
编辑:这是我的角色动作代码:
if(isAlive)
birdAnimation.update(dt);
if (position.y > 0 && isAlive) {
velocity.add(0, GRAVITY * dt);
}
velocity.scl(dt);
if(isAlive) {
position.add(MOVEMENT * dt, velocity.y);
velocity.scl(1 / dt);
}
if (position.y < 0)
position.y = 0;
if(position.y >= 1300 - sprite.getHeight())
position.y = 1300 - sprite.getHeight();