I would like to remove an object (which is a tile layer) from my scene whenever my character collides with that object. In the case it is an explosive box, where, whenever the character collides with the box, it will lose life, an explosion animation occurs and the box would be removed from the map. Any tips?
I already have a function for this, but I’m missing the part of removing the box from the scene.
This depends on what your explosive box actually is. If it’s a Game Object, you can just call the destroy method on it to remove it from the Scene. If it’s a tile on a Dynamic Tilemap Layer, you can use the removeTileAt method on the layer - something like tile.layer.tilemapLayer.removeTileAt(tile.x, tile.y) should work. Alternatively, you can use putTileAt to change the tile.
As for getting a reference to the explosive box, how is your bombCollide method being called? If it’s from a Collider (Arcade Physics), you’ll get the two colliding objects as arguments.
I saw the example you gave me, but I could not figure out how to apply it properly in my case. What I want to remove is effectively a Tile layer, because that’s how I defined it when I created the map in the Tiled editor. With this in mind, this box has the following properties in my game:
Can you give me an example using the information I provide? I’m new to this Game and Tiled stuff, I’m still not familiar with some procedures
Tile layers are Game Objects, so you can just destroy them. If you store bomba3 on your Scene as this.bomba3, you should be able to use this.bomba3.destroy() from your collision handler. Still, it would be helpful to see how you actually add the collision handler, especially if this is not the only bomb in the level.
That said, I’m not sure whether using one tile layer for each bomb you need is a good solution. It’s not efficient and it’d make it quite annoying to add more than one bomb. It would be easier, in the long run, to put all bombs on one dynamic layer and use tile callbacks along with the example I posted earlier.
I forgot to show how I was calling the function, my bad. Here it is:
Whenever there is a collision with the particular element, this is how the game should respond. Btw was incorrect in that a tile layer was a Game Objects. You were right, haha.
I noticed the explanation more or less, but I was seeing the code that you made available to me and in your case you are using dynamicLayer while I am using staticLayer. In the function you told me to see, you are making the call using coinLayer which is your dynamic layer. In my case would I have to make the call using (next image)?
It is for the variable bomba3 that I declare that it is a staticLayer
If I do something like this:
Tell’s me that bomb3 is undefined
If I do something like this:
Tell’s me that bomb3 is undefined…
I’m not really realizing how to solve this problem …