Hi, so in my game I have a bunch of boxes that do different things when broken, I have some of them in the TileMap object and I want to have it so when the player jumps on them and they break, different thing happens depending on what part of the Tile Map it was.
Not sure if I explained it properly, but I will explain it in another way
So I have one object called “Boxes” It has animations for different boxes, I can have it do different things in the events by using “If Object animation is X, do Y” and “If Object animation is B, do C” and it’s all using the same object.
I want to do that with the tile map but I have no idea how or if it’s even possible, mainly because there will be lots of boxes in the level and using the tile map painter is so much easier and better than the default GDevelop way which is drag and drop each object individually.
Is this possible? And if so how is it done?
Hi 7Elven,
i am not a professional, but you can access individual tiles by the collision mask. you can set a collision mask to an individual tile and if the player “hits” the tile, you can do an action on it.
if you have several actions you can access them by setting boole variables on the status you want to act.
Hello, Limmerick! I have set a collision mask for my tile object, 80x80, and I still don’t get how to do it, is it through these actions?
If so, can I have a simple example of how it’s done?
First, add a single tile to your map. it can be whatever you like, because you make it vanish from the screen.
but you add a collision to your player sprite, and choose the single tile, then follows your code… perhaps designing the bools you need to make something happen…
Dont forget to let let the tile vanish from the screen.
How will this be used to apply actions to a specific tile? Or is this a part of a tile and you can select it in the conditions? I’m a bit confused here
sorry my english is not very amusing
you define a global bool variable.
if the action is the collision, you set these bool to true, and call a new function by action of the changed bool variable. there you add the stuff you want to change.
Player hits tile, then bool set to true.
New event, that starts with the check of the bool variable on true, and so on…
You can get the ID of the tile below the player using point is inside or cast a ray. You could use collision or if the tilemap is a platform and the tile has a collision then you could use on floor.
Edit
In this example it changes the tile from 0 to 1.
I added 5 to the Y of the ray cast because I didn’t know which tile it would get from the Y since it’s at the edge of the tile.
is it part of an animation?
My object is a platform so I used “Players is on Platform”, and I think these IDs are already given by the tilemap object? I right clicked on the tile map objects in the object properties and they give me one number, 0,1,2 etc, so I assume these are the IDs
I tried to test it with this event expecting it to just delete the tile with ID 1, but it deletes all the tiles, did I do something wrong here?
Do you want to delete the entire tile map or just the tile that it collides with? You need to supply an x and Y for the condition.
You could then change that tile and/or spawn an object in its place or whatever you want to happen.
Your condition is for the grid. See my example, I used the one based on the scene coordinates. I used the x, y
The grid version would be good if you want to set or read the value using a variable and say repeat.
Otherwise, you probably want to use the condition that uses the screen coordinate.
Yes, I want to delete a specific tile that the player jumps on, not the whole tile, how do I get the scene coordinates? Is it the X and Y of where each tile is? Because that would defeat the point
There are 2 ways to get and set the tile ID. Either by grid or by screen coordinate. Grid is in reference to itself. The top corner I believe is 0,0. The scene coordinates is just that. The x, y on the scene. The function does the math for you and internally converts it to the tilemap’s grid.
For a platform, the x, y would be below the player. As I said earlier, you can use an object point or raycast to get that location. You could use any reference on the player and add to it. If the player is at 100,100 then the tile would be 100,100 + some type of offset.
This is my test. The black box is the player. The arrow points to the deleted box.
Alright, I tried the raycast and it did work, thanks a lot!