Tuesday, August 9, 2022
HomeGame Developmentjava - Array of sprite animation libgdx

java – Array of sprite animation libgdx


I am making an attempt to create a recreation for a college undertaking. In the principle menu, i animated a personality with this:

    spidey = new Texture("spidey.png");
    TextureRegion[][] tmpFrames = 
    TextureRegion.cut up(spidey,spidey.getWidth()/3,spidey.getHeight()/5);
    animationFrames = new TextureRegion[15];
    int index = 0;
    for (int i=0; i<5; i++){
        for (int j=0; j<3; j++){
            animationFrames[index++] = tmpFrames[i][j];
        }
    }
    animation = new Animation(0.15f, (Object[]) animationFrames);

But when i’ve an array of character like this:

    public void characters() {
    enemies = new Array<Enemy>();
    enemies.add(new Enemy(new Sprite(new Texture("img1.png")), spawn));
    enemies.add(new Enemy(new Sprite(new Texture("img2.png")), spawn));
    enemies.add(new Enemy(new Sprite(new Texture("img3.png")), spawn));
    enemies.add(new Enemy(new Sprite(new Texture("img4.png")), spawn));      
}

How am i able to animate all character?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments