When player collides with a layer delete only the block he touched


#1

Hey guys.

I’m making a little mario clone with phaser for a school project and its mostly working. I have been trying to get the question mark blocks to work for a couple days now but i can’t seem to get it done. So I made a new tilemap for the question mark blocks and put them in a layer. I activated collision for them with the game.physics.arcade.collide() command and made it so that when the player collides with the questionmark blocks it executes the spawnMushroom function where it is supposed to delete the block i just collided with but I cant get it to work. the closest thing i got was when it deleted all questionmark blocks.

Any advice on how to do it?


#2

I don’t totally remember but I think this is it:


#3

Try:
tilemap.removeTile(tile.x, tile.y, tile.layer.name);

I use a custom collision processing function when calling physics.collide, and one of the arguments to your collision func will be the “tile” objects.


#4

Thanks you two. Samme your example worked just the way I wanted thanks a lot.

With the map.setTileIndexCallback(26, hitCoin, this); command it works perfectly.