libgdx manager.update()阻止动画



我在项目中成功实现了一个gifdecoder,并为其与AssetManager一起编写了Gifloader。我能够将GIF加载到AssetManager中,也能够绘制它。但是,每次我尝试使用Manager.update()将GIF加载到我的AssetManager中,我再也无法绘制动画,只有非动画纹理。

这是我的代码,我希望有人有一个想法

public class Load implements Screen {
private SpriteBatch batch;
private Animation<TextureRegion> loadingAnimation;
private TextureAtlas atlasLoading = new TextureAtlas(Gdx.files.internal("atlas/loadingAnimation.atlas"));
float stateTime;
MainExecute lr;
public FileHandleResolver resolver = new InternalFileHandleResolver();
public AssetManager manager = new AssetManager();
private final Animation animation = GifDecoder.loadGIFAnimation(Animation.PlayMode.NORMAL, Gdx.files.internal("data/loading.gif").read());
public Load(MainExecute lr){
    this.lr = lr;
}
public Texture Bg1;
@Override
public void show() {
    Bg1 = new Texture(Gdx.files.internal("bggamescreen.png"));
    batch = new SpriteBatch();
    manager.setLoader(GIF.class,new Gifloader(resolver));
    manager.load("data/BackgroundAnim.gif",GIF.class);
    stateTime = 0f;
}


@Override
public void render(float delta) {
    if (manager.update())
    {

        lr.setScreen(new MainMenu(lr)); 
    }
    stateTime += delta;
  //  loadingAnimation = new Animation<TextureRegion>(0.5f, atlasLoading.findRegions("loading"),Animation.PlayMode.LOOP);
    TextureRegion currentFrame = (TextureRegion) animation.getKeyFrame(stateTime, true);

    batch.begin();
    batch.draw(Bg1,0,0,Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
    batch.draw(currentFrame, 0, 0, 200, 200);
    batch.end();



}
@Override
public void resize(int width, int height) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void hide() {
}
@Override
public void dispose() {
}

}

奇怪的代码,您在完成加载之前绘制动画。您需要等待加载动画,尝试这样的smth。

    if (manager.update())
    {
        loadingAnimation = new Animation<TextureRegion>(0.5f, atlasLoading.findRegions("loading"),Animation.PlayMode.LOOP);
        TextureRegion currentFrame = (TextureRegion) animation.getKeyFrame(stateTime, true);
        lr.setScreen(new MainMenu(lr)); 
    }

最新更新