Are there are any performance penalties/benefits in using a mask?
Context: Been reading the forums on efficient tile movement, and still not really sure the best way. Coming from a Flash/Flex background, here’s what I know for moving large tile maps:
- You should load the image into a Bitmap, and utilize a double-buffer to scroll, such as BitmapData.copyPixels. The rectangle you supply to copyPixels allows just that small section, say 320x240, to be shown. You aren’t physically moving anything, you’re just copying pixels.
Pro’s: Wicked fast
Con’s: doesn’t support half pixels, and you still have to composite other objects on top
- Whether you use a Sprite/MovieClip, or many Bitmaps on top of each other, you utilize the scrollRect. This makes a section of your large displayable area, and moves it merely based on changing the actual rectangle you’d like to view.
So, to move a map left, you’d go:
[as3]scrollRect = mapContainer.scrollRect
scrollRect.x = scrollRect.x - 2
mapContainer.scrollRect = scrollRect[/as3]
Pro’s: Pretty fast, and really easy to handle compositing (many objects in something like a Lua group); basically you aren’t really moving anything.
Con’s: Not as fast as blitting via BitmapData.copyPixels
- Mask and Move: You do like #2, but just create a mask, and move the container/group
Pro: Easy
Con: Not as efficient; even though something is masked, it’s drawn by the player/runtime, this includes the iOS export
- Dynamic Tile Draw, similar to the other thread and this blog post on creating tile maps in Lua: http://pixels.ph4.se/2010/10/tilemaps-with-corona-part2/
There doesn’t seem to be a way to do #1 in Lua/Corona. There doesn’t seem to be a rectangle display area equivalent to Flash Player’s scrollRect for #2. While #4 is an option, it’s not if you already have the tile maps built and don’t need to create a dynamically created tile area.
…so, I’m curious if #3 is a good or not. In playing with the new build (268), masking a group seems to work (little flaky on the emulator, good on the device).
So again, are there are any performance penalties/benefits in using a mask?
[import]uid: 23693 topic_id: 5718 reply_id: 305718[/import]
