具有无穷的/巨大的世界在ActionScript 2处理巨大、世界、ActionScript

2023-09-09 21:25:50 作者:屎壳郎i

如何无限/巨大的程序生成的世界最小的滞后动作2实现?在这样的游戏泰拉瑞亚或我的世界的例子。什么最好的方式去处理庞大的世界是这样呢?

How are infinite/huge procedural generated worlds achieved with minimal lag in actionscript 2? In a game like Terraria or Minecraft for example. What would the best way to go about handling huge world like this be?

显然,通过每一个块循环和移动他们的方式是行不通的。我试过把块到50×50'块',然后移动各块的,但结果是不靠近任何地方顺利,因为它应该是。

Obviously looping through every block and moving them that way won't work. I've tried placing blocks into 50x50 'chunks' and then moving each of the chunks, but the result isn't anywhere near as smooth as it should be.

有没有什么办法的地图完全禁用部分如果玩家不近呢?是否可以简单地将它们存储在内存中,并在需要时加载它们?

Is there any way to completely disable sections of the map if the player isn't near them? Would it be possible to simply store them in memory and load them when needed?

任何帮助是AP preciated,谢谢!

Any help is appreciated, thanks!

推荐答案

如果你的游戏是predominantly瓷砖为主,也就是说,世界上有相同大小的块为基本单位,它是最实用的存储你的世界在数组中。相反,由专人把你的块,像下面的数组可以存储对应于特定块类型的键:

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"

试想一下,在上面的例子中,游戏者可以只看到9块的时间,即

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"

这是玩家在世界阵列上的位置2,2。

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

每当玩家移动时,其相对于该排列位置被递增或分别递减。因此,向上移动,以将位置值下降到2,1并加载位于更远的北方块。

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.

从数组,你将检索到正上方的块水,水,水,并会放置三个影片剪辑。为以防万一,this回答展示了如何影片剪辑动态加载。

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.

此外,一个快速的方法来移动播放器的相对于世界的,而不是将整个世界对于球员,是改变值 _root。 _x _root._y

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绝对是伟大的与你想获得快速启动和运行简单的游戏上的工作,虽然AS3的性质可能更适合于动态加载多个对象。

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.