首页 > 解决方案 > LIBGDX 动画不播放或循环播放

问题描述

我有一个似乎是正确的硬币动画,但它不播放或循环,只出现第一张图像。我还有一个名为 Moedas(coins) 的类,我想使用它们的位置来设置动画 x 和 y,但如果我这样做,它甚至不会出现在屏幕上。这可能是什么原因造成的?

public Janela2 (MyGdxGame mgg){
   super(mgg);
   TextureAtlas at = new TextureAtlas("Arquivos.txt"); 
   coin1 = new Moedas(texture);
   coin2 = new Moedas(texture);
   TextureAtlas atlas = new TextureAtlas("Arquivos.txt");
   TextureRegion tr1 = new TextureRegion(atlas.findRegion("m321"));
   TextureRegion tr2 = new TextureRegion((atlas.findRegion("m322")));
   TextureRegion tr3 = new TextureRegion(atlas.findRegion("m323"));
   TextureRegion tr4 = new TextureRegion((atlas.findRegion("m324")));
   TextureRegion array[] = {tr1, tr2, tr3, tr4};
   time = 0f;
   ani = new Animation<TextureRegion>(0.5f,array);
   ani.setPlayMode(Animation.PlayMode.LOOP);
}
 public void render(float delta) {
    sp.begin();
    sp.draw(img, 0,0);
    sp.draw(player2, player2.getX(), player2.getY());
    Movimento.movement2(player2, boundingRecPlayer);
        if (Player.saimoeda(boundingRecCoin, boundingRecPlayer)) { 
    //collision method for testing if the player has touched the coin
            sp.draw(img, 0, 0);
            Movimento.movement(player, boundingrecp);
            sp.draw(player2, player2.getX(), player2.getY())
        } else {
            time = Gdx.graphics.getDeltaTime();
            TextureRegion t = ani.getKeyFrame(time, true);
            sp.draw(t, 50, 50);//static x and y because Moedas.x and Moedas.y doesnt work
    }
    sp.end();
}

@Override
public void dispose() {

   super.dispose();

 }
}

标签: androidlibgdx

解决方案


推荐阅读