0
votes

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?

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?

Any help is appreciated, thanks!

1
loading chunks = storing them in memory. But of course you could have a flag to enable/disable the handling of those chunks. Also, why are you "moving each of the chunks"? Once a chunk is generated, its position does not change. - Simon Forsberg
Try to move the objects inside the world instead of the entire world. Not even Minecraft or Terraria moves the world. - Simon Forsberg
I don't understand why you are moving the chunks at all. When you create a chunk, you should give the chunk a "chunk index". For example, chunk (0, 1) has the blocks in x-range 0-49 and y-range 50-99. Once this chunk is created, the chunk itself should not move. If the player moves, you move the player. You don't move the chunk. - Simon Forsberg
I suggest you separate the "model" from the "view". Don't show all things in the view at once. Only show the stuff that are close to the player and update that view when the player moves. Otherwise your view object would be waaaay too big. (What you're trying to do here is not very simple, but if you are a somewhat experienced programmer you will manage to do it. But I don't think a project like this is good for beginners). - Simon Forsberg
May I ask why you use AS2 instead of AS3? - Lars Blåsjö

1 Answers

0
votes

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.