Hi everyone, I was searching but unable to find an topic that was related to this one.
I'm trying to create an animated sprite. I have it working when I create a new FlxSprite and add all the animations then play the animation(look at MenuState lines 21-26). However I am unable to get the animations to work when I create a new Hero object that extends the FlxSprite class. I originally wanted all the animation code in the constructor of the Hero object but I've been just experimenting trying to get it to happen at all (MenuState lines 9-13). I was able to specify which frame index I want and it changed to the correct frame index. It just seems that play won't actually start the process. Does anyone know what might be the issue?
5 class MenuState extends FlxState
6 {
7 override public function create():Void
8 {
9 var hero = new Hero(100, 100);
10 hero.loadGraphic("images/manwalkdown.png", true, 33, 86);
11 hero.animation.add("test", [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 10, true);
12 add(hero);
13
hero.animation.play("test");
14
15 var upplayer : FlxSprite = new FlxSprite();
16 upplayer.loadGraphic("images/manwalkup.png", true, 31, 85);
17 upplayer.animation.add("up", [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 10, true);
18
upplayer.animation.play("up");
19 add(upplayer);
20
21 var downplayer : FlxSprite = new FlxSprite();
22 downplayer.loadGraphic("images/manwalkdown.png", true, 33, 86);
23 downplayer.animation.add("down", [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 10, true);
24 downplayer.x = 200;
25 add(downplayer);
26
downplayer.animation.play("down");
27
28 super.create();
29 }
5 class Hero extends FlxSprite {
6 public var currentMesh : NavMesh;
7 public var targets : Array<Vector2> = new Array<Vector2>();
8 public var targetMeshes : Array<NavMesh> = new Array<NavMesh>();
9
10 public function new(newX : Int, newY : Int) {
11 super(newX, newY);
12