libGDX manager.update()阻止动画

时间:2019-03-05 19:54:55

标签: java animation libgdx gif

我在项目中成功实现了gifdecoder,并为其编写了一个gifloader,以便将其与assetmanager一起使用。我可以将gif加载到资产管理器中,也可以绘制它。但是每次我尝试使用manager.update()在我的assetmanager中加载gif时,我再也不能绘制动画了,只能绘制非动画纹理。

这是我的代码,希望有人有主意

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() {

}

}

1 个答案:

答案 0 :(得分:0)

奇怪的代码,您正在绘制动画,然后再完成加载。您需要等待加载动画,像这样尝试一下。

    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)); 
    }