I have a procedural 2d game which extends in all directions, on the surface similar to Terraria. When a player moves their camera close to the edge of the currently loaded terrain, I trigger an expand event, which loads new chunks of terrain. Each chunk is an N×N section of tiles. When I do this I get a stutter of about 1 second due to the cost of procedurally generating the new tile set.

How can I avoid that delay?

Currently, all new chunks are loaded in the same iteration of the update loop (bad I know). My current idea is to create a queue to store the chunks and only render 1 chunk per game update.

  • \$\begingroup\$ wich language/engine? \$\endgroup\$ Commented Sep 3, 2015 at 9:32
  • 4
    \$\begingroup\$ Multithreading the generation. Generating it in smaller chunks per frame, not waiting till they get close to the edge but starting as soon as they're not in the center of the loaded map. Lots of options \$\endgroup\$
    – Elva
    Commented Sep 3, 2015 at 11:47

1 Answer 1


Start generation early; if a player gets within 3 screen widths of the edge of the generated map start generating more chunks on that edge 1 chunk at a time.

Focus generation on the area the player is likely to go. That means follow the walkable terrain and defer sky and underground for later (when they return to the location or linger for a while).

Multi-thread the generation. You can do that easily by doing the expensive creation in the other thread and then just paste the data into the level data in the update loop.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .