Problem with libgdx animation

So, for whatever reason my animation isn’t updating, i’ve tried googling it and they all keep saying the same thing which i’ve done over and over again. I don’t know if it’s something small that i keep missing.

private void createAnimations() {
		TextureRegion[] runFrames = new TextureRegion[4];
		TextureRegion[] idleFrames = new TextureRegion[4];
		TextureAtlas knight = assetManager.get("entities/knight.atlas", TextureAtlas.class);
		TextureAtlas knightIdle = assetManager.get("entities/knight_idle.atlas", TextureAtlas.class);

		runFrames[0] = (knight.findRegion("knight_m_run_anim_f0"));
		runFrames[1] = (knight.findRegion("knight_m_run_anim_f1"));
		runFrames[2] = (knight.findRegion("knight_m_run_anim_f2"));
		runFrames[3] = (knight.findRegion("knight_m_run_anim_f3"));
		
		idleFrames[0] = (knight.findRegion("knight_m_idle_anim_f0"));
		idleFrames[1] = (knight.findRegion("knight_m_idle_anim_f1"));
		idleFrames[2] = (knight.findRegion("knight_m_idle_anim_f2"));
		idleFrames[3] = (knight.findRegion("knight_m_idle_anim_f3"));

		runAnimation = new Animation<TextureRegion>(5f, runFrames);
		idleAnimation = new Animation<TextureRegion>(0.1f, knightIdle.findRegions("knight_idle"), PlayMode.LOOP);
	}

I tried two different ways to see if it would change anything. The knight idle atlas has the proper indexing, to make it easier to animate, while the knight atlas just contains all of the frames.

public void render(SpriteBatch batch, float delta) {
		createAnimations();
		float elapsedTime = 0;
		
		batch.begin();
		
		elapsedTime += delta;
		currentFrame = runAnimation.getKeyFrame(elapsedTime);

		player.applyLinearImpulse((playerSpeedX - player.getLinearVelocity().x) * player.getMass(),
				(playerSpeedY - player.getLinearVelocity().y) * player.getMass(), player.getWorldCenter().x,
				player.getWorldCenter().y, true);

		this.position = player.getPosition();

		batch.draw(currentFrame, position.x - 10 * 0.5f * UNIT_SCALE,
				position.y - 10 * 0.5f * UNIT_SCALE, .6f, 1);
		
		Gdx.app.log("PLAYER", "Animation: " + idleAnimation.getKeyFrame(elapsedTime));

		batch.end();

	}

There are no errors being thrown at all, all it shows is the first frame of the animation and doesn’t change. createAnimations wasn’t originally called in the render method i just moved it to see if it would change anything

[quote]createAnimations wasn’t originally called in the render method i just moved it to see if it would change anything
[/quote]
The only thing that does is recreate all Animation objects every frame, you obviously don’t want to do that since it prevents the Animation from progressing.

The root cause for your issue is that you are not advancing elapsedTime further than one delta time step. This is because you declared and initialized elapsedTime inside the render function itself, you need to declare it inside the class scope so that it’s actually accumulating the time over multiple frames.

Here’s how it should look like:

// Call this once at the beginning of your game.
private void setupAnimationsAndStuff() {
    createAnimations();
}

// Just let this accumulate, the Animation class handles the time overflow, depending on the PlayMode selected.
private float elapsedTime = 0f;

public void render(SpriteBatch batch, float delta) {
    
	elapsedTime += delta;
	currentFrame = runAnimation.getKeyFrame(elapsedTime);
	
	player.applyLinearImpulse((playerSpeedX - player.getLinearVelocity().x) * player.getMass(),
		(playerSpeedY - player.getLinearVelocity().y) * player.getMass(), player.getWorldCenter().x,
		player.getWorldCenter().y, true);
	
	this.position = player.getPosition();
	
	batch.begin();
	batch.draw(currentFrame, position.x - 10 * 0.5f * UNIT_SCALE,
		position.y - 10 * 0.5f * UNIT_SCALE, .6f, 1);
	batch.end();
	
	Gdx.app.log("PLAYER", "Animation: " + idleAnimation.getKeyFrame(elapsedTime));
}

Just read the LibGDX source code for the Class you have problems with. It’s not rocket science.

Here’s the Animation Class for starters: Animation.java

Of course it’s something that simple haha, thanks so much for the help!