Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
    
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... –  jSepia Sep 20 '10 at 11:01

2 Answers 2

up vote 6 down vote accepted

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

share|improve this answer
    
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." –  jSepia 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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.