I've made an animation class that creates an animation for a player. However, I'm wondering how I can change the animation depending on where the player is currently moving? Heres my animation class:
public class AnimationTest extends ApplicationAdapter{
Batch batch;
private TextureAtlas textureAtlas;
private Animation animation;
private float elapsedTime = 0f;
private Sapien player;
public void create (Batch batch, String string, Sapien player) {
this.batch = batch;
this.player = player;
textureAtlas = new TextureAtlas(Gdx.files.internal(string));
animation = new Animation(1f/10f, textureAtlas.getRegions());
}
public TextureAtlas getTextureAtlas(){
return new TextureAtlas(Gdx.files.internal("Player/Angle1/running/running.atlas"));
}
@Override
public void dispose() {
batch.dispose();
textureAtlas.dispose();
}
@Override
public void render () {
elapsedTime += Gdx.graphics.getDeltaTime();
//Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw((TextureRegion) animation.getKeyFrame(elapsedTime,true),player.getX(),player.getY(),75,75);
batch.end();
}
I currently call create() and render() in another class.
public TiledTestTwo (int scale){
this.scale = scale;
}
@Override
public void create () {
View.createInstance(this.scale);
float w = Gdx.graphics.getWidth();
float h = Gdx.graphics.getHeight();
player = new Player(animationTest.getTextureAtlas(),400,400,2);
playerController = new PlayerController(player);
camera = View.getInstance().createCamera(w, h);
animationTest.create(View.getInstance().getBatch(), "Player/Angle1/idle/angle1IdleSheet.atlas", player);
rounds = new Rounds(scale,w, h);
}
@Override
public void render () {
//Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
//animationTest.render();
camera.update();
View.getInstance().setView(camera);
View.getInstance().render();
animationTest.render();
movableSubject.notifyUpdate();
collisionController.checkCollisions(View.getInstance(), player, this.scale);
ZombieObserver.getInstance().playerLocation((int) player.getX(),(int) player.getY());
rounds.checkNewRound(player);
}