4

I have a world that has 7,500,000 tiles in it. The world is 1500x5000 and each tile is 16x16 pixels. If I want to load a game and I just loaded all the tiles that would take a long time. Is there a way just to load the tiles near the player? Like how terraria renders all its tiles.

jujumumu
  • 350
  • 4
  • 12

2 Answers2

4

To handle such a large amount of tiles, you will need to split your world into smaller TileMaps (either manually or by using a script) and load/unload chunks as the player moves. This is similar to how Minecraft loads the world, except it's in 2D this time. To my knowledge, Terraria does the same thing.

Since you need TileMaps to be loaded/unloaded entirely (rather than just shown/hidden), you can't use the VisibilityNotifier or VisibilityEnabler nodes here. However, you may be able to use InstancePlaceholder to your benefit, as it's intended to mark "placeholder" nodes that can be loaded on demand. To do this from the editor, you can right-click any node in the scene tree dock then enable Load as Placeholder.

If loading chunks at runtime still causes stuttering, you'll also have to use the ResourceInteractiveLoader class to load TileMap resources in the background.

Calinou
  • 889
  • 8
  • 14
  • What do you mean by load/unload the tiles in each chunk. Do you mean going through each tile in that tilemap and setting it as empty? – jujumumu Feb 07 '20 at 01:16
  • 2
    No, just instance TileMap nodes and load the tile data inside as you go by setting its `tile_data` property. To unload a chunk, call `queue_free()` on the TileMap node. Since TileMap data isn't a Resource (but rather just a PoolIntArray), you will have to figure out some way to save/load it. ConfigFile might be usable for this purpose. – Calinou Feb 07 '20 at 08:09
  • Whats the point of instancing a new tilemap then setting the tile data but to unload it you queue_free(). Why can't you just have one tilemap and just set the tile data there. And to unload it just set it to be empty? Is this inefficient? – jujumumu Mar 01 '20 at 16:20
0

Don't use different tilemaps, instead just use FastNoiseLite to procedurally generate your map and just load/unload the chunks/regions where your player's position is standing.

Yunnosch
  • 26,130
  • 9
  • 42
  • 54
  • 1
    Please expand on how this would help solve the problem. – DBS Oct 13 '22 at 09:05
  • Yes. Procedural generate your map and just load/unload the chunks/regions where your player's position is standing – Alan Rodriguez Flores Oct 14 '22 at 10:06
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 24 '22 at 11:21