Post news RSS Chunk Loading for Large Worlds

I've begun implementing a chunk loading system since my larger levels can have a lot of instances that need to be initialized.

Posted by on

Now that I've started building a bigger overworld, it's become necessary to implement some sort of chunk loading system. The initialization scripts for the walls objects take up the most CPU in the first step when a new room loads. This is because they all run a script that autotiles them.

I've begun implementing the chunk loading system. There is a 3x3 grid of active chunks that moves around with the player and initializes the wall objects as it reaches new chunks that haven't been loaded. Right now it only works with the wall objects, but I plan to use it for as many objects as is feasible. I would also like to use chunk loading on as many levels as I can (not just the overworld), because I have a few levels that are large or have a lot of wall objects and I don't want them to be excessively laggy on the first frame the player enters the room.

Below you can see what the chunk loader looks like in action. Each wall is on a 32x32 grid, and each chunk is 96x96. I use a 2D array to keep track of which chunks are loaded, and in the GIF below you can see that I've drawn a transparent red overlay on all of the unloaded chunks. You can also see the wall tiles getting initialized with their autotile script as the player (and active chunk area) moves around.

The chunks will be much larger in the actual game so that you don't see any of the loading going on, but for demonstration and debugging purposes, I have left them small. Also, the grids and red overlay will not be drawn in-game.

2017 07 27 - Slime King

As a bonus, in this GIF, you get to see some of the new overworld and some of the new door entrance sprites :)

Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.