Hello! What is the best way to create an infinite horizontal map? I want to create a map that resembles the “Library” map in the game Vampire Survivors. My map should be limited at the top and bottom and expand horizontally to infinity.
I tried using Parallax2D together with TileMapLayer to reflect the drawn tile map, and everything works fine except for collisions. As I understand it, using them together breaks the collisions I set up in TileMapLayer.
It would also be interesting to hear how to optimize something like this.
Collisions within Parallax2D isn’t officially supported (since it can easily get really funky, quickly), but you can just double the collisions up, and it should work.
Wow, excuse me, could you tell me how you doubled the number of collisions?
I just drew the tiles twice. Notice that it’s twice the viewport size even before I set the repeat on the Parallax2D? Parallax only renders things twice visually. Nodes don’t actually get duplicated (which would be horrible!), so I just copied the tiles over. This makes sure that it’s infinitely repeating, but also that there’s actual tiles with collision underneath that repeat. I used the same tiles, but you could also just paint with invisible tiles that have collision too. Just a neat little trick!
2 times is just the default. The number of repetitions is controlled with the repeat_times property. Parallax2D — Godot Engine (4.5) documentation in English
I suggest using a normal TileMapLayer for the world the player interacts with combined with chunking to implement the infinite scroll. If you limit your parallax layers to only background visuals, then I think you shouldn’t need collision in the parallax nodes at all.
If you search for tilemaplayer chunking, you should get some good results for how it’s implemented.
That’s true, but the number of times isn’t really important in this case, because no matter how many times you set it to repeat, it’s still just repeating it visually. No nodes are duplicated. I usually don’t recommend it in general since repeat_times is only really meant to be used as a sledgehammer workaround for zooming out when you don’t have assets made to work with your resolution.
If you want a robust solution, a custom setup or custom TileMapLayer chunking (as you mentioned) is the better way to go, but the Parallax2D trick does work for a quick trick.