简体   繁体   中英

Animation not animating in Libgdx

So I have 2 characters in my game and for both I've set animation like this:

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

you have to create a new Player instance then return it;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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