mp_grid_create

This function creates an mp_grid for the motion planning functions.

It returns an index that should be stored in a variable for use in all the other MP grid function calls. The x and y coordinates indicate the position of the top-left corner of the grid, hcells and vcells indicate the number of horizontal and vertical cells to be created within the grid, and cell width and cell height indicate the size of the cells in pixels. You can create and maintain multiple grid structures at the same moment if you need them for different things, but be aware that each grid will require memory, and the more cells they have the more memory they will require. Also note that the MP functions are quite processor heavy to use so the more often you call them and the higher the cell resolution then the more likely you are to have a drop in performance.

 

Syntax:

mp_grid_create(left, top, hcells, vcells, cellwidth, cellheight);

ArgumentTypeDescription
leftRealStarting x coordinate of the mp_grid in the room
topRealStarting y coordinate of the mp_grid in the room
hcellsRealNumber of horizontal cells that the mp_grid will contain
vcellsRealNumber of vertical cells that the mp_grid will contain
cellwidthRealThe width (in pixels) of each individual cell of the mp_grid
cellheightRealThe height (in pixels) of each individual cell of the mp_grid

 

Returns:

MP Grid ID

 

Example:

global.grid = mp_grid_create(0, 0, room_width / 32, room_height / 32, 32, 32);

The above code creates a global variable "grid", then generates an mp_grid and assigns its index (id) to that variable for use in all further mp_grid function calls. The grid covers the room, with a cell resolution of 32x32 pixels. This means that, for example, in a room that is 640x480, the grid would contain 300 cells: 20 horizontal cells (640 / 32) multiplied by 15 vertical cells (480 /32) gives 300 cells.