Moving A mp_grid

L

Logan Bevans

Guest
So im using a grid and a path system for an enemy ai. in my game the room changes when i move how would i go about moving the grid to my view this is the code for obj_grid:Create
how do i keep the height and width variable current with the position of the object im using them in the creation of the grid but if i move away from the height and width variables they dont change since its only in the create even but if i put the code in the step event wouldn't it just create a bunch of grids?



var cell_width = 32;
var cell_height = 32;

height = x + 640;
width = y + 480

var hcells = height; //Change to a view
var vcells = width; //Change to a view

global.grid = mp_grid_create(x,y,hcells, vcells, cell_width, cell_height);
//global.grid = mp_grid_create(0,0, hcells, vcells, cell_width, cell_height);

//Adding Path Collsions
mp_grid_add_instances(global.grid,obj_solidblock,false);
 
L

Logan Bevans

Guest
Right Now i have this
if x != 640 && y != 480{
mp_grid_clear_all(global.grid);

height = x + 640;
width = y + 480



global.grid = mp_grid_create(x,y,hcells, vcells, cell_width, cell_height);
}

but its a memory leak is there a better way or how to fix the memory leak
 

Evanski

Raccoon Lord
Forum Staff
Moderator
I would first start by having the hcells and vcells be the width and height of your room, there for you dont need to worry about the view as the enemy will path find with in it so long as your player is.
I would update it every so often in a alarm event rather then the step.

mp_grid_clear_all(global.grid);
That doesnt get rid of the grid that just makes it empty, your just creating a whole crap load of grids and then making them empty
 
L

Logan Bevans

Guest
I would first start by having the hcells and vcells be the width and height of your room, there for you dont need to worry about the view as the enemy will path find with in it so long as your player is.
I would update it every so often in a alarm event rather then the step.


That doesnt get rid of the grid that just makes it empty, your just creating a whole crap load of grids and then making them empty
Ohh Ok Ill try that out Thanks
 
Last edited by a moderator:
L

Logan Bevans

Guest
I would first start by having the hcells and vcells be the width and height of your room, there for you dont need to worry about the view as the enemy will path find with in it so long as your player is.
I would update it every so often in a alarm event rather then the step.


That doesnt get rid of the grid that just makes it empty, your just creating a whole crap load of grids and then making them empty
Would i just use global.grid = mp_grid_create(x,y,hcells, vcells, cell_width, cell_height); to update it i was worried using this would create a bunch of grids and lag
 
Last edited by a moderator:
Top