2015-11-01 53 views
0

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

我使用此代码

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中,但在运行时失败。

这是我在运行时获取,而在猫

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); 
... 

我错过了什么吗?

回答

0

Neko对var初始化非常明智,所以您应该检查frames_per_row的值。

什么是pixels?定义了pixels.width?尝试使用Math.floor()而不是cast(pixels.width/16, Int)

+0

Math.floor导致相同的结果。 像素是BitmapData,在图形加载(loadGraphic())时定义。 每个var都被完全初始化。 – filipp8

+0

尝试在var frames_per_row之前跟踪像素和pixels.width:Int = cast(pixels.width/16,Int);并填写后跟踪动画数组 – Andrew

+0

我必须纠正自己。 Math.floor做了诡计。这怎么可能? frames_per_row总是被追踪为6,同时演员和Math.floor ... – filipp8

相关问题