This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+2 votes

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.

in Engine by (31 points)

1 Answer

0 votes
Best answer

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 :)
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.

by (29,510 points)
selected by

Thank you, this gives me something to work with.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.