jujumumu
jujumumu

Reputation: 390

Godot - how can I load 7,500,000 tiles without it taking so long?

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.

Upvotes: 4

Views: 4780

Answers (2)

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.

Upvotes: 0

Calinou
Calinou

Reputation: 949

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.

Upvotes: 4

Related Questions