mp_grid_clear_cell

This function can be used to clear a specific "cell" of an MP grid. Cells are not calculated as room coordinates, but rather as grid coordinates, where (0,0) is the top let corner of the grid. this means that to clear a cell at a specific position in the room, we must change the x and y coordinates into cell coordinate dividing them by the resolution of the MP grid. The code example below shows how this works.

 

Syntax:

mp_grid_clear_cell(id, h, v);

ArgumentTypeDescription
idMP Grid IDIndex of the mp_grid that is to be used
hRealHorizontal position of the cell to clear
vRealvertical position of the cell to clear

 

Returns:

Boolean

 

Example:

with (obj_Box)
{
    mp_grid_clear_cell(grid, floor(x / 32), floor(y /32));
    instance_destroy();
}

The above code will make all "obj_Box" destroy themselves and have them mark the cells they occupied in the mp_grid indexed in the variable "grid" as free. In this example, we find the appropriate cell by taking the x/y coordinate of the object and dividing them by the resolution of the grid (using floor to keep the values as integers).