Actionscript 2 large tile-based maps creating lag

2019-02-26 20:57发布

问题:

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?

回答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.