Most Amercians have a 4 day weekend this week. As such, I plan on updating some of my older tile-based games over the weekend in AS3. Both Flash 8, and Flash 8.5 have the really cool new objects, Bitmap & BitmapData. This allows you to utilize 1 bitmap to display a bunch of moving sprites instead of hundreds of sprites/movieclips. The advantage of this is lower CPU usage.
The tilebased engines I've made in the past always had the CPU bottleneck, no matter what approach I took. Whether it was a bunch of tiles in 1 movieclip masked, or a small set that has their new tiles on the side that is revealed created, whilst the others that leave the viewing area destroyed on the fly... they all suffered from 60-90% CPU usage. However, using blitting, where I draw a bunch of tiles & detail to 1 bitmap, and double-buffering, where I blit to 1 bitmap offstage, and then just use copyPixels to show a smaller bitmap onstage using scrollRect & cacheAsBitmap... it uses 0-2% CPU! Now, while this is great for tiles, you quickly get back into high CPU usage by adding sprites (flash.display.Sprite vs. flash.display.MovieClip) on top of that. So, I figured I could use the old composition model that a lot of people favor with MovieClips. Instead of binding to a class by extending MovieClip: class MyClass extends MovieClip I could instead pass in a reference to the class' constructor, keeping the class, and the view it draws to, seperate. In this case, I'd actually pass in a Bitmap object. That way, the class can draw to the bitmap, and this bitmap can be shared amongst many movieclips. Methods like move, setSize, etc. will use invalidate to ensure they only redraw their changes once to the actual bitmap itself. function move(p_x, p_y) { x = p_x; y = p_y; invalidate(); // runs next frame, only once } ...here's where things break down for me. I'm not used to coding like this, so don't really know the best pratice ways to go about it. For example: - how do I handle depth? "last draw wins", so do I manage depth myself? - how do I handle move, and x and y change operations? They don't affect the bitmap the sprite is blitting to, but they do affect the one they are on... events the parent listens to maybe? - going off of the above, who is the parent? Suddenly, there is some magical render somewhere that handles the invalidation & redrawing once per frame... what's the best way to do this? - How do you sub-class sprites? Like, do they just call their super methods, and pray that invalidation handles all the intricacies of multiple drawing renderings? It may seem like a lot of work, but the performance increases I'm seeing in Flash 8 and Flash 8.5 are unbelievable using this methodology to redraw the stage with many objects, and fits perfectly in with tile-based games. I asked this on gamedev.net, but got no response. If anyone has any advice, articles, or books, I'd be most interested to hear about them! Thanks if you can help. --JesterXL _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders