DaxHR
DaxHR

Reputation: 683

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?

Upvotes: 1

Views: 102

Answers (1)

Methnani Bilel
Methnani Bilel

Reputation: 1385

the problem is in this line: this.player = new Player(animation);

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

Upvotes: 1

Related Questions