Tile not being replaced when called to?

In the game im making when the player hits a tile I want the specific tile number to be recorded. So i have made the code:

	pos = go.get_position()
	x_tile = math.ceil(pos.x/16)
	y_tile = math.ceil(pos.y/16)
	tile = tilemap.get_tile("/level#Level_1", "level", x_tile, y_tile) 
	if not (self.last_tile == tile) then
		print(tile)
		self.last_tile = tile
	end

When i hit the tile it printed out 84

So i wrote the code below which should remove the tile from the running game when i hit it. I’m not getting any errors but when my player hits the tile it just stays there? Have i coded it incorrectly?

	if not (self.last_tile == tile) then
		if tile == 84 then
			tilemap.set_tile("/level#Level_1", "level", x_tile, y_tile, 0)
		end 
			self.last_tile = tile
	end

by doing some debugging i have found that instead if replacing the current tile 84 adds tile 0 one space above the tile 84. Do you know how i can change my code so tile 0 replaces tile 84 instead

I’d like to ask you to only assign forum posts as “bugs” if you think there is a bug in the Defold engine/editor, not if there is a potential bug in your code.
Please choose category “Questions” for your questions.

Regarding your question, we don’t know how you calculate the x_tileand y_tilein your second snippet, so it’s hard to say.

Are you sure that the tile coordinates are the same in the two snippets?

1 Like

I checked what you said and when i subtracted the y_tile by 1 in the new if loop it got the new tile to overlay on tile 84, which is what i wanted. I’m not sure why this happened but i can ask this in the questions catagory :wink:

Maybe this tilemap example will help?

1 Like