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 if
s 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?
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.