# Is frustum culling necessary in a Flash/AS3 game?

I'm making a 2D game where the map will be scrolled frequently, and only a small part of it will be visible at any time.

Which implementation would run faster?

• The naive way: Make the map a single huge MovieClip and move it around.
• The elegant way: Split the map into
multiple chunks and use a frustum
culling algorithm to render only the ones that are visible.

Now that I think of it, this question boils down to whether Flash does its own frustum culling on big MovieClips.

• Couldn't you could just try it both ways, profile it, and use the faster one? – BigSandwich Sep 19 '10 at 3:59
• I was hoping I wouldn't have to... – User not found Sep 20 '10 at 11:01

Flash is actually pretty good at handling "frustum culling". You should use the scrollRect property for this: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObject.html#scrollRect

If you plan to use a Image for your world map, you should be aware of the Bitmap-size limitations of the Flash player. If you target player 9, the limits are 2880x2880 pixels. Player 10 and up can handle images with a pixel sum of max. 4095^2 pixels (see: http://kb2.adobe.com/cps/496/cpsid_49662.html).

If you think your map might exceed these limits, I think it would be a good idea to implement some tiling on your own.

Update: Here's an article that explains scrollRect a bit better: http://www.gskinner.com/blog/archives/2006/11/understanding_d.html

• Thanks for the last link about scrollRect. This sentence in particular answered my question: "Vector masks are very inefficient in Flash, because the whole DisplayObject is rendered, not just the visible portion." – User not found Sep 20 '10 at 9:52

Spend time implementing culling now. You'll be happy you did.

Should you choose not to, at least avoid making it a MovieClip as there's no technical reason it shouldn't be anything more than a Sprite instance.