Better method for playing animations
This commit is contained in:
parent
ef4117672c
commit
e985102e80
@ -130,7 +130,7 @@ public class GladiatorBrawler extends ApplicationAdapter {
|
|||||||
Sprite player2 = SpriteLoader.loadSprite(Name.PLAYERIMG, 1, 0, 64, 64);
|
Sprite player2 = SpriteLoader.loadSprite(Name.PLAYERIMG, 1, 0, 64, 64);
|
||||||
SpriteSequence sequence = new SpriteSequence(1).addSprite(player1).addSprite(player2);
|
SpriteSequence sequence = new SpriteSequence(1).addSprite(player1).addSprite(player2);
|
||||||
renderedObject.addSequence("Idle", sequence);
|
renderedObject.addSequence("Idle", sequence);
|
||||||
renderedObject.setCurrentSequence("Idle");
|
renderedObject.playAnimation("Idle");
|
||||||
player.add(renderedObject);
|
player.add(renderedObject);
|
||||||
player.add(new CPhysics());
|
player.add(new CPhysics());
|
||||||
player.getComponent(CPhysics.class).body = body;
|
player.getComponent(CPhysics.class).body = body;
|
||||||
|
@ -38,6 +38,21 @@ public class CRenderedObject extends Component {
|
|||||||
return spritesequences.get(key);
|
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() {
|
public float getCurrentFrame() {
|
||||||
return currentframe;
|
return currentframe;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user