views:

487

answers:

1

I would like to do simple (looping) animation (moving, changing alpha etc) in haXe (flash9). I don't have anything that resembles frames in my library, just single frame assets.

Since I am a beginner. I am not necessarily looking for a sophisticated framework. I would be happy with something quick & dirty. Maybe ifs checking the frame (class variable) and linearly interpolating the values.

class MyClass extends Sprite {
    static var frame:Int = 0;
    static inline var framerate:Int = 25;

    static function main() {
        var app:MyClass = new MyClass();
        flash.Lib.current.addChild(app);
    }

    private function new() {
        super();

        // init assets here

        var myTimer:Timer = new Timer(1000/framerate);
        myTimer.addEventListener(TimerEvent.TIMER, animate);
        myTimer.start();
    }

    function animateForeground(event:TimerEvent) {
        frame = (frame + 1) % 1000;

        // set new values depending on frame
    }

}

I know the basic idea of keyframe animation. What I am looking for is more about how to structure this part of the program.

Can you please give me some pointers on how should I proceed?

+3  A: 

If you want to do animations I would very much recommend using a tweening library, although I understand that you might want to learn the basics before "cheating" past them.

I would recommend hooking up your animations to the ENTER_FRAME event instead of a timer running at the same speed as your framerate. There's really no need to decouple these two, since the timer isn't any more reliable than the ENTER_FRAME event, and there's no need in moving stuff around if it can't be seen anyway.

Also, I don't think you should focus that much on "keyframe" animation. That is a useful concept when you have keyframes, if you don't it's way more practical just to do what feels like the best way to implement this.

I would put some code in here, but I'm having a little bit of a hard time coming up with any since I'm not really sure what you're trying to achieve here.

grapefrukt
Thanks. I didn't get the part about ENTER_FRAME, since I'll have always one frame (I'm still having a hard time understanding flash object structure). I wish there was a practical way to create frames on the fly. I'm checking out tweening...
muhuk
ENTER_FRAME is fired each time a frame is rendered, "modern" flash development concerns itself very little about keyframes as opposed to oldschool actionscript 1.
grapefrukt
Yes, ENTER_FRAME gets fired at your fps speed, even if you have no frames.
Mk12