简体   繁体   English

动画在 Libgdx 中没有动画

[英]Animation not animating in Libgdx

So I have 2 characters in my game and for both I've set animation like this:所以我的游戏中有 2 个角色,并且我都设置了这样的动画:

public void createPlayer(){

        TextureRegion[] regions = new TextureRegion[4];
        regions[0] = new TextureRegion(new Texture(Gdx.files.internal("player1.png")));
        regions[1] = new TextureRegion(new Texture(Gdx.files.internal("player2.png")));
        regions[2] = new TextureRegion(new Texture(Gdx.files.internal("player3.png")));
        regions[3] = new TextureRegion(new Texture(Gdx.files.internal("player4.png")));


        final Animation animation = new Animation(.05f, regions);

        this.player = new Player(animation);
        gameStage.addActor(player);
        player.setPosition(30, 300);

And for the actual player animation is not working, and for the other character it is working.对于实际的玩家动画不起作用,而对于另一个角色它正在起作用。 I don't know why I'm getting this bug because I'm using exactly the same code..我不知道为什么会出现此错误,因为我使用的是完全相同的代码。

Any ideas?有任何想法吗?

the problem is in this line: this.player = new Player(animation);问题出在这一行: this.player = new Player(animation);

you have to create a new Player instance then return it;你必须创建一个新的 Player 实例然后返回它;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM