6
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ Couldn't you could just try it both ways, profile it, and use the faster one? \$\endgroup\$ Sep 19, 2010 at 3:59
  • \$\begingroup\$ I was hoping I wouldn't have to... \$\endgroup\$ Sep 20, 2010 at 11:01

2 Answers 2

6
\$\begingroup\$

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

\$\endgroup\$
1
  • \$\begingroup\$ 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." \$\endgroup\$ Sep 20, 2010 at 9:52
2
\$\begingroup\$

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.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .