2

I'm wondering what the best way to go about creating large, tile-based maps in flash with actionscript 2 would be.

With my current code, any maps over 35x35 (1225 movieclips) start to lag. The maps are created from a simple multi-demensional array, eg.

var map = [[95,23,25,23,16,25],[95,23,25,23,16,25],[95,23,25,23,16,25]];

The program simply creates a movieclip of a tile, goes to the appropriate frame and places the tile relative to the player's location. Each tile has one property, that is 'walkable' which is either true or false which determines if the player can walk on it or not. These tile are childs of a holder movieclip. When the players moves, the holder movieclip is moved(and however many tiles that are contained in it).

What would be the best way to reduce the lag on large-scale maps?

  • This is one of three related questions by the same user, the questions are: [AS2 Best way to decrease lag when dealing with several movieclips with onEnterFrames](http://stackoverflow.com/questions/16848043), [Dealing with infinite/huge worlds in actionscript 2](http://stackoverflow.com/questions/19060661/dealing-with-infinite-huge-worlds-in-actionscript-2), [Actionscript 2 large tile-based maps creating lag](http://stackoverflow.com/questions/15583420/actionscript-2-large-tile-based-maps-creating-lag) – Simon Forsberg Sep 28 '13 at 10:50

1 Answers1

1

If only a small portion of the large map is visible at a time, I would only create the child movieclip tiles for tiles that are currently visible, and then add/remove them as the viewport moves around.

On the other hand, if you're displaying the whole thing at once, you'll probably need to graphically copy all of the tiles onto a single large movieclip using the BitmapData class. Then you can remove the movieclip tiles so that Flash only has to scroll one large movieclip.

Depending on what your tiles are, you can also experiment with setting cacheAsBitmap to true along with assigning opaqueBackground on all the movieclips involved.

Dan Wich
  • 4,923
  • 1
  • 26
  • 22
  • Only a portion of the map is visible at a time, so the removing the movieclips and re-adding them/setting visible to false would be the most ideal option. However I've tried for a few hours and I can't seem to get it work. Any suggestions? – Mike Hunter Mar 23 '13 at 08:32
  • If I used the BitmapData class wouldn't the movieclip properties ie. .walkable disappear? – Mike Hunter Mar 23 '13 at 23:08
  • Yes, you'd need to keep track of .walkable separately from the visible tiles. I'm assuming they're already in some sort of array that you were assigning to the movieclips? You would instead need to access that original array every time you did a .walkable check. – Dan Wich Mar 24 '13 at 20:29