How to get the position on the tilemap of a tile, to later delete it?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ArAdev
:warning: Old Version Published before Godot 3 was released.

Hi, I´m trying to get the position of a tile inside a tile map to later set the cell to -1. The problem is that I can´t get the pos. I´m using a sprite to try to get the position. I can set a cell to -1 with set_cell() if I have the position before, but I need to delete the tile in-game when the sprite “collides” with it (get the same pos).
I tried using something like this:

var tile = self.get_cell(self.world_to_map(sprite.get_global_pos()))

But it says that the engine expects two arguments. How can I solve the problem? Thanks in anticipation.

Method get_cell() wants the x and y as separate not as one vector2.

Hooni | 2017-12-17 19:27

Yes, I know that, but I don`t know how to get the position on the tile map of the tiles (not the global position in the game)

ArAdev | 2017-12-17 20:10

Do you mean that you don’t know how to get the x and y components from your world_to_map(sprite.get_global_pos()) ? You just add .x to get the x component and after a comma add the same thing for the y.
God damn I hate typing on mobile…

Hooni | 2017-12-17 20:37

Thanks a lot, it worked!. I was having too much problems with this.

ArAdev | 2017-12-17 20:52

:bust_in_silhouette: Reply From: umsee

Yeah, I’m also trying to do the same thing, so as to get the effect of the undulating tiles of Axiom Verge, I don’t know if it would solve your problem but the two varaiables it expects is the int x, int y of the tile in the grid.

7,3 is the x and y

{forgive me if you could see the image I am fairly new to this thing, this was the image Screenshot from 2019-10-25 22-45-00.png - Google Drive}

you should try the TileMap.get_cellv(), you could pass your sprite or KinematicBody2D’s global_position as a parameter to it and you could get the colliding tile’s index.

Then you could use something like set_cell() or you could just go set_cellv() from the start and bypass this process entirely almost for the same effect