I develop a 2D shooter game with lots of objects and aggressive scrolling.
QUESTION: which way is better?
CHOICE 1 - use native Flash rendering:
- derive game objects from Bitmap, use existing x, y, width, height, bitmapData
- add all objects as children UIComponent.addChild(...) to sccreen
- clip visible area using "scrollRect"
CHOICE 2 - write custom rendering using "bitmap + copyPixels"
- use own game object with x, y, width, height, bitmapData
- add a Bitmap to a screen, take bitmapData from it
- redraw every ENTER_FRAME: bitmapData.lock(), iterate over game objects and copyPixels() into bitmapData, then bitmapData.unlock()
- custom clipping: do not render out of screen objects
Here in this question some people complain that "bitmap + copyPixels()" is slow.
EXPERIMENT: I have implemented both techniques:
- main_1.swf - native
- main_2.swf - custom
Please, try them and tell which one is better (faster, smoother, eats less CPU).
Wait until there will be at least 250 enemies (counter above the screen).
UPDATE: Try to open Task Manager (or $top) and see overall CPU usage
UPDATE 2: I've changed the code, now creeps spawn much faster.