I have everything up to date and I'm using HaxeFlixel to experiment some assets import and automation. What I'm trying to accomplish is to get frames from a sprite sheet and automate the add.animation process. For example, I need the first row of the sheet to form the run animation, the second one another animation etc...
I use this code
class ExampleSprite extends FlxSprite
{
public function new(X:Float=0, Y:Float=0, ?SimpleGraphic:Dynamic)
{
super(X, Y, SimpleGraphic);
loadGraphic(AssetPaths.examplesprite__png, true, 16, 16);
// THIS OBVIOUSLY WOULD WORK
//animation.add("run", [0, 1, 2, 3, 4, 5], 10, true);
// THIS HAS PROBLEM WHEN RUN WITH NEKO
var animationArray:Array<Int> = new Array();
var i:Int = 0;
var frames_per_row:Int = cast(pixels.width / 16, Int);
while (i < frames_per_row) {
animationArray.push(0*frames_per_row + i);
i++;
}
animation.add("run", animationArray, 10, true);
animation.play("run");
}
}
I want to calculate how many frames are there in a row and, in a single cicle, put the right frame numbers into its own animation array. When I add the animation to the FlxSprite I'm passing the array containing the numbers, instead of hard coding everything.
THIS WORKS as expected in html5, flash, windows. It builds in neko but fails at runtime.
This is what I get at runtime while debugging in Neko
Invalid array access
Called from Array::__get line 291
Called from flixel.animation.FlxBaseAnimation::set_curIndex line 34
Called from flixel.animation.FlxAnimation::set_curFrame line 186
Called from flixel.animation.FlxAnimation::play line 112
Called from flixel.animation.FlxAnimationController::play line 493
Called from Player::new line 147
Called from Player::$init line 16
Called from PlayState::create line 44
...
When I populate the array, curiously, this works animationArray.push(i);
and this fails animationArray.push(0*frames_per_row + i);
I need the second writing because I have to populate multiple arrays at once
animationArray0.push(0*frames_per_row + i);
animationArray1.push(1*frames_per_row + i);
animationArray2.push(2*frames_per_row + i);
...
Am I missing something?
Neko is very sensible to var initialization, so you should inspect the value of frames_per_row
.
What is pixels
? Is pixels.width
defined? Try to use Math.floor()
instead of cast(pixels.width / 16, Int)
.