Dealing with infinite/huge worlds in actionscript 2

强颜欢笑 提交于 2019-12-02 11:06:54
interpolack

If your game is predominantly tile-based, that is, the world has same-size blocks as its base unit, it is most practical to store your world in an array. Instead of placing your blocks by hand, an array like the following can store keys that correspond to specific block types:

"grass" "grass" "grass" "water" "water"
"grass" "water" "water" "water" "water"
"grass" "grass" "woods" "woods" "woods"
"grass" "grass" "woods" "woods" "woods"
"grass" "grass" "woods" "woods" "woods"
"grass" "grass" "grass" "woods" "woods"

Imagine that in the above example, the player can only see nine blocks at a time, i.e.

"grass" "woods" "woods"
"grass" "woods" "woods"
"grass" "woods" "woods"

This is the player at position 2,2 on the world array.

Whenever the player moves, its position with respect to the array is incremented or decremented respectively. So moving upward to would decrease the position value to 2,1 and load the blocks that are located farther north.

From the array, you would retrieve that the blocks immediately above are "water" "water" "water", and would load three water movieclips. Just in case, this answer shows how to load movieclips dynamically.

Also, a quick way to move the player with respect to the world, instead of moving the entire world with respect to the player, is to change the values _root._x and _root._y.

In the end, if the game is too graphics intensive, have you considered traversing the world on a 'room-based' system, where the player's position is not fixed, and every fifty blocks or so goes to a new screen of blocks? That would easily cut down on the strain.

AS2 is absolutely great for working with simple games that you want to get up and running quickly, although the nature of AS3 may be more suited for loading many objects dynamically.

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