开发者

DisplayObjects as animation frames? AS3

How can I use displayObjects as animation frames?

I have six symbols in my library I want to animate with a timer. The advantage would be the ability to change the speed of the animations, and the elimination of the messy timeline.

The only drawback is the initial setup of the objects in the library. I've tried switch/case design patterns, visible=true, and z-depth, but I can't get it to work properly. Any answers?

//setup code
var timer:Timer = new Timer(100, 20);
timer.addEventListener(TimerEvent.TIMER, countdown);
function countdown(event:TimerEvent) {
    myText.text = String(0 + timer.currentCount);
}
timer.start();

var frame1:Fr开发者_如何学编程ame1 = new Frame1;
addChild(frame1);
//frame1.visible = false

var frame2:Frame2 = new Frame2;
addChild(frame2);
//frame1.visible = false

var frame3:Frame3 = new Frame3;
addChild(frame3);
//frame1.visible = false

var frame4:Frame4 = new Frame4;
addChild(frame4);
//frame1.visible = false

var frame5:Frame5 = new Frame5;
addChild(frame5);
//frame1.visible = false

var frame6:Frame6 = new Frame6;
addChild(frame6);
//frame1.visible = false


Something like this. This is written for readability, not performance or expandability, but should get you on the right track.

var frames:Array = [
    new Frame1(),
    new Frame2(),
    new Frame3(),
    new Frame4(),
    new Frame5(),
    new Frame6()
];

for each (var frame:Sprite in frames) {
    addChild(frame);
}

var timer:Timer = new Timer(100);
timer.addEventListener(TimerEvent.TIMER, countdown);
function countdown(event:TimerEvent) {
    myText.text = String(0 + timer.currentCount);
    var currentFrame:int = timer.currentCount % frames.length;
    for (var i:int = 0; i < frames.length; ++i) {
        frames[i].visible = (i == currentFrame);
    }
}
timer.start();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜