GameMaker destroy a tile with collision

S

sadegh93

Guest
hello.
i want to destroy a tile which have collision with special object (like a bullet)
is this possible with GML and how?
thanks a lot
 
G

Gronbal

Guest
From what I know you would have to assign your tile to a object to make this work.

If this is the case, you could do different things. The easiest being the use of the builtin collision. Here you can set a collision between two objects, and destroy one or both upon collision.

Example code in a collision event:

For destroying only one:
Code:
//In the collision event. Will destroy the object in which the event is located.
instance_destroy();
For destroying both the bullet and tile:
Code:
//In the collision event. 

//This will destroy the other part of the collision, could be the tile.
with(other) {
    instance_destroy();
}

//Will destroy the object, in which it is written
instance_destroy();
 

Miradur

Member
Hi, you can change the tiles, but you cannot delete them completely but change it to zero
for for none display. From the Help File:

tile_set_index()

Code:
var lay_id = layer_get_id("Tiles_sky");
var map_id = layer_tilemap_get_id(lay_id);
var mx = tilemap_get_cell_x_at_pixel(map_id, mouse_x, mouse_y);
var my = tilemap_get_cell_y_at_pixel(map_id, mouse_x, mouse_y);
var data = tilemap_get(map_id, mx, my);
var ind = tile_get_index(data);
data = tile_set_index(data, irandom(23));
tilemap_set(map_id, data, mx, my);

Miradur
 
Top