[Update: June 2, 2007]
Version 2.0 is now live.
I finally managed to find enough free time in the past couple couple weeks to refactor/port my animation system to AS3. The performance is great and I learned a lot of little things about AS3 in the process of making it. Before I get into details about what I learned, issues I ran into, and some new features I added, let’s have a look at the architecture.
Not exactly a UML diagram, but white boards are awesome and the marker colors even match the colors of my blog (tacky yet cool nonetheless).
Similar to the architecture of my AS2 animation system, a framebuffer and renderer are used. You may notice something new in the diagram however, the RenderMethod object. This is the highlight feature of my first release of the system; you can specify whether you want to use a timer or the enter frame event individually for each animation. To me, being able to use the right render method for the right occasion is invaluable, and will certainly pay off in larger projects.
The new event system in AS3 is fantastic, so there was no need to build my own event system this time around. The only other new object that needs special attention is the Global object. In order to make the enter frame usage possible, a listener must be added to a display object which is inside a display container. So if you created a sprite object and added an event listener, the enter frame event wouldn’t occur until you added it to a display container. This is where the Global object comes into play. In your main application class, the best practice would be to start off setting the global stage reference in the Global object right away, that way it is always available. However, since that creates a dependency, my animation system checks each new animation that is created to see if the target object is a display object. If it is, the global stage reference is extracted from it and set for all other objects to use.
You will notice a much smoother animation using a timer as your render method over the enter frame event. This is because the default refresh rate is set to 14 milliseconds, the ideal rate for a project running at 30 frame per second. You can pass your own custom refresh rate into the constructor of an animation manager as well. When a timer is used, the display is manually updated independent of the frame rate. This is why the animation appears so much smoother than one rendered using the enter frame event. Essentially, you are seeing an animation at around 60 frames per second, but this extra load on the processor only lasts for the short duration of the animation. In a case where you are doing something like a pulse animation on an object, it’s probably wiser to use the enter frame event, since the pulse animation runs until you remove it. The default render method for all animations is a timer, so if you prefer enter frame, you can set the default render method at the top of the animation manager class.
Again, to me, the benefit to using my system over other animation systems out there (though I do believe this is the first one available in AS3) is the manner in which the code is written and maintained. It’s written in a strict object-oriented fashion, so it can be easily extended upon with new animation types and features.
The link to download the zip file is below. If you have any comments, feedback, or bug reports, I’d love to hear from you. Hopefully you will find it handy and also a great reference for learning AS3. Enjoy.
NOTE: If you don’t already have the Adobe Flash Professional 9 ActionScript 3.0 Preview, you can download it from Adobe Labs here.23 comments