• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

SOLVED Mp_grid add tile instead of instance?

Evanski

Raccoon Lord
Forum Staff
Moderator
I'm setting up a path-finding system using mp_grids, I'm very familiar with setting up and using mp_grids

mp_grid_add_instances(id, obj, prec);
using this we can add instances to avoid to the grid

but I was wondering if instead of instances I could use tiles
I'd like to start using tile collisions for my games instead of object based ones (for room barriers and such)

I think the only way is by using
mp_grid_add_rectangle(id, x1, y1, x2, y2);
to draw rectangles around groups of certain tiles I deem as collsion

Is there any good way to go about doing this?

Thanks, -Evan
 

Simon Gust

Member
This?
 

Evanski

Raccoon Lord
Forum Staff
Moderator
This?
Well that was a good start until I found
if tile_layer_find(TILE_DEPTH, (i * cell_size) + (cell_size / 2), (j * cell_size) + (cell_size / 2)) != -1 // Gets the center position of the tile cell
doesn't work anymore
 

Simon Gust

Member
Code:
var lay_id = layer_get_id("whatever");
var map_id = layer_tilemap_get_id(lay_id);

var cell_size = 32;
var w = room_width / cell_size;
var h = room_height / cell_size;

for (var i = 0; i < w; i++) {
for (var j = 0; j < h; j++) {
    if (tilemap_get_at_pixel(map_id, i * cell_size, j * cell_size) > 0)
    {
        mp_grid_add_cell(GRID, i, j);
    }
}}
 

Evanski

Raccoon Lord
Forum Staff
Moderator
Code:
var lay_id = layer_get_id("whatever");
var map_id = layer_tilemap_get_id(lay_id);

var cell_size = 32;
var w = room_width / cell_size;
var h = room_height / cell_size;

for (var i = 0; i < w; i++) {
for (var j = 0; j < h; j++) {
    if (tilemap_get_at_pixel(map_id, i * cell_size, j * cell_size) > 0)
    {
        mp_grid_add_cell(GRID, i, j);
    }
}}
That works so well, Thank you so much
 
Top