|
|
|
|
Attention |
Topic was automatically imported from the old Question2Answer platform. |
|
Asked By |
Ktotoetoia |
Hello everyone, I’m creating a 2D strategy, but I don’t know how I can interact with the tilemap in the game, for example, so that when I click on a certain tile, it changes
|
|
|
|
Reply From: |
StopNot |
Here is an example. I haven’t tested the code so there might be issues. Also it’s not pretty.
if event is InputEventMouseButton:
if event.pressed:
var pos = event.position
var x = int(pos.x / 20)
var y = int(pos.y / 20)
var clicked_tile_pos = Vector2(x, y)
# gets the tile index from the tileset in the given position
var current_tile = map.get_cellv(clicked_tile_pos)
# sets the tile to index in the given position
map.set_cellv(clicked_tile_pos , new_tile)
Hopefully this helps.