From e985102e806fac63858dccfc0140ec9ecc399d99 Mon Sep 17 00:00:00 2001 From: Allexit Date: Fri, 10 Apr 2015 19:10:08 +0300 Subject: [PATCH] Better method for playing animations --- .../com/saltosion/gladiator/GladiatorBrawler.java | 2 +- .../gladiator/components/CRenderedObject.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/core/src/com/saltosion/gladiator/GladiatorBrawler.java b/core/src/com/saltosion/gladiator/GladiatorBrawler.java index 444d699..908f2cf 100644 --- a/core/src/com/saltosion/gladiator/GladiatorBrawler.java +++ b/core/src/com/saltosion/gladiator/GladiatorBrawler.java @@ -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; diff --git a/core/src/com/saltosion/gladiator/components/CRenderedObject.java b/core/src/com/saltosion/gladiator/components/CRenderedObject.java index d9c9d08..def9b08 100644 --- a/core/src/com/saltosion/gladiator/components/CRenderedObject.java +++ b/core/src/com/saltosion/gladiator/components/CRenderedObject.java @@ -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; }