0 votes

Hi
I've just started learn godot and i trying to make side scroll platformer. I set up yellow tile and i want to replace this tile with green one, when player collide with this tile. How i can do that? Or maybe i should use tilemap only for static, non-interactive elements, and make interactive elements with sprites or something?

in Engine by (20 points)

2 Answers

+1 vote
Best answer

The ideal is to use tilemaps for static tiles only, if are used to make tilemaps with some advanced editor like Tiled, then you may also be used to parse the tilemap and spawn game elements replacing special tiles (animated, triggers, etc.).

Using the corresponding nodes for interactive objects will make the level design a lot more flexible and easier to update than depending on tiles.

That said, you can do many things with tiles, working like old times using the tilemap as if it were an array, it has some functions to translate coordinates, getting used cells and many other things for tile-dependant designs.
Also parse the tilemap on runtime to replace tiles with other nodes.

by (7,868 points)
selected by
+1 vote

You can modify a TileMap in the game the same way you modify it in the editor.
You have to use the set_cell function: http://docs.godotengine.org/en/stable/classes/class_tilemap.html#class-tilemap-set-cell

The function expects a tile index, but you can also use the tile name by looking into the TileSet:

var tile_index = tilemap.get_tileset().find_tile_by_name("your_tile_name")
tilemap.set_cell(x, y, tile_index)
by (27,902 points)
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 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 webmaster@godotengine.org with your username.