Expanding/Creating tilemaps to generate a path?

I need to generate a visual path my player will follow. However, I want to create it with the data of the turns in the path.

So I have the data
turns[1] = right
turns[2] = left
… and so on

So, I think the best way to make it would be to generate a tilemap based off of the data, and make it scroll across the screen (if there is a better way, then, please, I’m open to suggestions!).

However, I am not going to define every xy co-ordinate in this path beforehand, but create it from a script at runtime to save time.

The tilemap will be assigned to an object, and the object will be moved as the hero moves. (Or is it better for the tilemap to stretch across the screen, and reset every frame update?)

If I calculate the dimensions of the path, how would I create a new one (from code)?
If I don’t calculate the dimensions, such as in an endless path (e.g. endless runner), how could I continuously add to the path?

Or if these questions sound over your head, simply, what is the best/correct way to implement a tilemap in a game?

I’ve really got no idea if this is what you want.,
But I believe you can do paths in Tiled.
Have a look at setthebet’s commando tutorial on live coding. I haven’t watched all of it, but I think he was going to talk about it.
I hope he does as I need to do something like it.

I skipped through some of the procedurally created map tutorial. It kinda is what I’m looking for.

I just need to know how to set the bounds of a tilemap.

Another problem I’m having is, How do I scroll a map?

If you want to procedurally create a tilemap using tilemap.set_tile() you need to first create an empty tilemap but make sure to put tiles in the four corners of tilemap to mark it’s bounds. Trying to call set_tile() with coordinates outside the bounds will not work (I can’t remember if nothing happens or if it results in an error).

You can scroll the map in many different ways, but I guess the most common approach would be to attach a camera component to your player or some other game object and move that to change the viewport.

1 Like

Thanks!

From the tutorials, I was thinking that I always generated objects and destroyed them as they entered and exited the screen, not move the camera around :stuck_out_tongue:

The approach with a static player and moving ground and obstacles works well in an infinite runner, but less so in other types of games.