Finally had time for an update! Here are the animated sprite classes that i've mention before, which are being used in my nearly finished game. I've done some basic testing and built the main base for my animation system (i'll extend it to animated tiles for backgrounds later). I couldn't find an animated bitmap class on the web for Actionscript 3 that i could use for my specific requirements - so i've made my own. Heres a quick run down of the features:
- Simple XML animation format
- Unlimited number of "states" to define different actions for each sprite
- Each frame can be any size rectangle, located anywhere on the animation image (not just repeating rectangles like most systems)
- Possiblity to have huge sprites (can use multiple images for a single sprite - only limited to 2880 bitmap size maximum per asset)
- A frame can be located anywhere on the image and can reuse a frame multiple times in a single state aswell as across multiple states
- Optional handle/hotspot for handling sprites instead of top left
- Minimizes overdraw by specifying smallest rectangles not just fixed width & size for each frame (handy for bin packing images)
- No loop, normal looping or ping-pong style animation looping
- Play animation forwards or backwards
- Start animation at any frame, and jump to any frame
- Allows both animated sprites & bitmaps (sprite has a child bitmap)
- Clone animatedBitmaps to save processing the XML file multiple times
- FRAME_CHANGED and ANIMATION_COMPLETE events
- Play animation once, loop animation infinitely or specify number of loops
- Each frame can have a specific number of milliseconds delay, allowing fine control over complex animations
- Sprite animation playback speed can be adjusted to slowdown or speedup the whole animation on the fly
- Set current state by statename as well as index
- Uses ENTER_FRAME instead of timers for animation update (useTimer option if you want to use timers for specific animations)
- Stagelayer object to separate animated sprites/bitmaps into layers (needed for ENTER_FRAME and handy for collisions)
- 4 Different Rendering methods for memory use vs speed (and for different requirements as one type doesn't fit all)
- FRAME_BUFFER_REFERENCE (uses original bitmapData & scrollRect)
- FRAME_BUFFER_OVERSIZED (uses a single growing bitmapData & copyPixels)
- FRAME_BUFFER_CACHED (uses a seperate bitmapData for each frame & caches it when first generated with copyPixels)
- FRAME_BUFFER_UNIQUE (uses a new bitmapData & copyPixels everytime the frame changes)
- Uses frame time delta with smoothing for smoother animation (includes option to turn it off)
I haven't really had enough time to write a demo for this library - i have started working on a simple tool in flex to help you generate the xml file by marking out rectangles on an image, but i haven't got enough time to finish this at the moment (this is why i was holding up releasing this before now as i wanted to release them both together). I'd appreciate it if you use this set of classes to find any bugs, or suggest improvements so i can improve this as i add other parts to my component library. You can use this source code in any project you like and make changes, but please don't release my library before talking to me - thats all i ask. Heres a little demo i knocked up for you to see it in action:
I found the sprite sheet on a webpage by The_Protagonist but can't find the page or the link now (it had some other nice sprites on there as well) so if someone finds the page can you post the link in the comments. The animated sprite is based on a tween sprite which uses TweenMax by Jack Doyle (which itself is based on TweenLite also by Jack Doyle) but you could modify it easily to use which ever one of the many tween packages you like the most (although through my tests TweenMax is one of the best if not the best for ease of use and functionality for size). I've also converted and included the Easing functions by Robert Penner for use with TweenMax.
The demo has an example XML file, i can post a tutorial and a better demo in the future if people need help with it, but it should be fairly straight forward. If one value is the same from the previous frame you can simply leave it out and the loader will use the cached value (not between states though, just frames). The library is in a seperate zip to the demo as i plan to add to the library (including some unreleased ui classes that i already have) and it makes it simple for updating.
Let me know if you find this useful, or find any bugs as i'm using this in my game that should be finished in a week or so!
Wed, 07/23/2008 - 09:51
Thanks so much for putting this up! I'd been having difficulty understanding Display Objects in AS3 versus AS2 movieclips--and how to even start creating animations without the flash ide--this was/is so helpful. Blessings!
Thu, 07/10/2008 - 23:03
I did create those test ones by hand - but I am working on a sprite xml creator in flex but it's been a fairly steep learning curve for adding things like dragging marques and resizing them and it's been on hold a while due to other workloads. I have a half finished tile system in the pipeline as well (which i need for an up coming game) so you might not see a big update for a while, but hopefully it will be a good one with the sprite tool, shortly followed by a decent tile engine (fingers crossed!).
Wed, 07/09/2008 - 13:57
Just downloaded your code and took a quick look. Looks solid! Did you create the XML file by hand? Would be nice to have a tool to examine a sprite sheet and create the corresponding XML file. Thanks for sharing!
Post new comment