Looping Tilemaps, Stitching Tilemaps

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By saguaro
:warning: Old Version Published before Godot 3 was released.

I am trying to find a way to seamlessly loop tilemaps in Godot. I want the player to be able to travel left or right indefinitely.

Currently, I’m using two warp areas to move the player from one end of the tilemap to the other. When the player’s coordinates are changed with set_pos() it takes the child Camera2D a few seconds to catch up. My solution was to free the camera node, move the player, and create a new camera node. This method isn’t ideal–both ends of the map must have a viewport-length of repeated tiles and the warp areas must be lined up just-so. The camera cannot have drag margins. It’s going to look weird if other objects are in the viewport.

I think I’m approaching this problem from the wrong angle. I’m hoping for advice on a better way to implement this as well as a way to stitch small maps together, if such a thing is possible.

:bust_in_silhouette: Reply From: Zylann

I generally see two ways of looping a tilemap:

A. Move the tilemap (or quadrants) to preserve space connexity, so there will be no teleport of the player.
In this case, you have to replicate the tilemap on the 8 directions (up, down, left, right, diagonals). To make this easier, you can slice it in chunks so when the player goes on the left edge, you teleport chunks from the right edge to the left (including objects inside it).

B. Teleport the player like you said and render placeholders of the map when reaching the edges, if needed.
Use cameras to render on a texture, and use that texture to display what’s in the world the other side of the “loop portal”. So you can see enemies moving the other side, for example :slight_smile:
Camera problems could be solved by implementing your own camera logic in GDScript so you can handle the teleport. Or, you could have multiple cameras, but use only one as current (the others can render to textures like I said above). They all move the same, but offset by the size of the map. When you need a teleport, switch current camera.

Thank you, this gives me something to work with.

saguaro | 2016-04-11 20:27