Haxe: keyframe animation without frames

I would like to make a simple (looping) animation (moving, changing alpha, etc.) in Haxe (flash9). I have nothing that resembles frames in my library, only individual frame resources.

Since I am a beginner. I'm not necessarily looking for a complex structure. I would be happy with something quick and dirty. Perhaps if checking frame (class variable) and linear interpolation of 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. I am looking more about how to structure this part of the program.

Could you give me some guidance on how I should proceed?

+4
source share
2 answers

If you want to make an animation, I would highly recommend using the tweening library, although I understand that you might want to learn the basics before you “cheat” them.

I would recommend attaching the animation to the ENTER_FRAME event instead of a timer running at the same speed as the frame rate. Actually there is no need to separate these two, since the timer is no more reliable than the ENTER_FRAME event, and there is no need to move things around if they are still not visible.

Also, I don’t think you should focus on keyframe animations. This is a useful concept when you have keyframes, if you are not more practical, just do what seems like the best way to implement this.

I would add the code here, but it’s a little difficult for me to come up with something, since I'm not quite sure what you are trying to achieve here.

+4
source

It's probably worth reading chapter7_tweening.pdf from Robert Penner’s book, although it is now very outdated in terms of code, it covers the concept of tweening.

But maybe you should not reinvent the wheel ...

Feffect is a good tweening engine, Actuate is easier to use and fast. Using macros for tweening is probably the best approach, but it may be a little tricky to get started ( tinkerbell ).

0
source

All Articles