Actionscript 2 large tile-based maps creating lag

家住魔仙堡 提交于 2019-12-02 02:53:45

问题


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.



来源:https://stackoverflow.com/questions/15583420/actionscript-2-large-tile-based-maps-creating-lag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!