Better method for playing animations

This commit is contained in:
Allexit 2015-04-10 19:10:08 +03:00
parent ef4117672c
commit e985102e80
2 changed files with 16 additions and 1 deletions

View File

@ -130,7 +130,7 @@ public class GladiatorBrawler extends ApplicationAdapter {
Sprite player2 = SpriteLoader.loadSprite(Name.PLAYERIMG, 1, 0, 64, 64);
SpriteSequence sequence = new SpriteSequence(1).addSprite(player1).addSprite(player2);
renderedObject.addSequence("Idle", sequence);
renderedObject.setCurrentSequence("Idle");
renderedObject.playAnimation("Idle");
player.add(renderedObject);
player.add(new CPhysics());
player.getComponent(CPhysics.class).body = body;

View File

@ -38,6 +38,21 @@ public class CRenderedObject extends Component {
return spritesequences.get(key);
}
public void playAnimation(String key) {
playAnimation(key, 0);
}
public void playAnimation(String key, int startingframe) {
if (spritesequences.containsKey(key)) {
currentSequence = key;
currentframe = startingframe;
return;
}
String[] s = (String[]) spritesequences.keySet().toArray();
currentSequence = s[0];
currentframe = 0;
}
public float getCurrentFrame() {
return currentframe;
}