Animating GameObject

File names and frame sizes may vary on your side.

public class SceneNameHere extends Scene {

    private GameObject player = new GameObject(this, "Player");

    private Animation[] playerAnimations = new Animation[] {
        new Animation("Idle", new SpriteSheet(new Sprite("player_idle.png"), 16, 16), 500),
        new Animation("Walk", new SpriteSheet(new Sprite("player_walk.png"), 16, 16), 500),
    };

    private Animator playerAnim = new Animator(playerAnimations);

    public Scene(Game game) {
        super(game);
    }

    @Override
    public void Initialize() {
        player.setPosition(new Vector2(128, 128));
        player.setScale(new Vector2(16, 16));

        // Change Active Animation
        playerAnim.setActiveAnimation("Idle");
        player.addComponent(playerAnim);
    }

    @Override
    public void Update() {

    }

    @Override
    public void Render(Graphics g) {

    }

}

Last updated