HaxeFlixel:FlxSprite动画在运行时因Neko目标而失败

时间:2015-11-01 14:50:39

标签: arrays haxe openfl haxeflixel neko

我拥有最新的一切,我正在使用HaxeFlixel来试验一些资产导入和自动化。 我想要完成的是从精灵表中获取帧并自动执行add.animation过程。 例如,我需要工作表的第一行来形成运行动画,第二行需要另一个动画等......

我使用此代码

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");
    }

}

我想计算一行中有多少帧,并且在单个cicle中,将正确的帧编号放入其自己的动画数组中。 当我将动画添加到FlxSprite时,我正在传递包含数字的数组,而不是硬编码所有内容。

这可以在html5,flash,windows中按预期工作。它在neko中构建,但在运行时失败。

这是我在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
...

当我填充数组时,奇怪的是,这有效animationArray.push(i);,而animationArray.push(0*frames_per_row + i);失败 我需要第二次写作,因为我必须一次填充多个数组

animationArray0.push(0*frames_per_row + i);
animationArray1.push(1*frames_per_row + i);
animationArray2.push(2*frames_per_row + i);
...

我错过了什么吗?

1 个答案:

答案 0 :(得分:0)

Neko对var初始化非常敏感,所以你应该检查frames_per_row的值。

什么是pixelspixels.width是否已定义?尝试使用Math.floor()代替cast(pixels.width / 16, Int)