如何制作SIMPLE动画精灵动作?

时间:2013-02-26 17:31:38

标签: flash actionscript air flashdevelop flash-builder

我无法找到任何很好的解释创建动画精灵的简单方法。假设我有2个.png文件出现兔子跑:

rabbit1.png 和  的 rabbit2.png

 [Embed(source='assets/rabbit1.png')] public static const R1: Class;
 [Embed(source='assets/rabbit2.png')] public static const R2: Class;

我知道我可以创建精灵并添加到这样的帧:

var rabbit1:Bitmap = new R1();
var rabbit2:Bitmap = new R2();

var bunny:Sprite = new Sprite();
bunny.addChildAt(rabbit1,1);
bunny.addChildAt(rabbit2,2);

没关系,但如何以简单的方式为它制作动画? (与我们一起创建额外的xml文件)

谢谢!

1 个答案:

答案 0 :(得分:1)

理想情况下,你会创建一个类,比方说,'SimpleAnimation',但如果你不想有另一种方式(使用你的代码)

var rabbit1:Bitmap = new R1();
var rabbit2:Bitmap = new R2();

var bunny:Sprite = new Sprite();
var currFrame:int = 0;
bunny.addChildAt(rabbit1,0);
bunny.addChildAt(rabbit2,1);
bunny.getChildAt(1).visible = false;

bunny.addEventListener(Event:ENTER_FRAME, onBunnyFrame);
function onBunnyFrame(e:Event):void
{
    var maxFrame:int = bunny.numChildren;
    bunny.getChildAt(currFrame).visible = false;
    currFrame++;
    currFrame = currFrame % maxFrame;
    bunny.getChildAt(currFrame).visible = true;
}