For those of you who want to Center your paths, here is a modification of the script provided in the Example and the script that centers it:
Replace the old
astar_getpath script with this:
//astar_getpath(startx,starty,endx,endy,center?)
{
var ar0,ar1,ar2,ar3,pathstring;
ar0 = floor(argument0 / global.astarR_cellwidth);
ar1 = floor(argument1 / global.astarR_cellheight);
ar2 = floor(argument2 / global.astarR_cellwidth);
ar3 = floor(argument3 / global.astarR_cellheight);
// Find the Path from the DLL
pathstring = external_call(global.astarR_getpath,ar0,ar1,ar2,ar3);
if(pathstring != '')
{
// Replace temporary function names
pathstring = string_replace_all(pathstring,"a(",")astar_addpoint(");
pathstring = string_replace_all(pathstring,"e(","astar_addpoint(");
pathstring = string_replace_all(pathstring,"b(",")astar_endpath(");
global.astarR_path = path_add();
execute_string(pathstring);
// Center the Path?
if(argument4)path_center_grid(global.astarR_path,global.astarR_cellwidth,glo
bal.astarR_cellheight);
// Return the Path Id
return global.astarR_path;
}
// Otherwise, return a blank string
return '';
}Here is the script that is also needed.
//path_center_grid(path,w,h);
// Written by DFortun81
{
var i,x1,y1,s1;
for(i = 0;i < path_get_number(argument0);i += 1;)
{
x1 = floor(path_get_point_x(argument0,i) / argument1) * argument1 + argument1 / 2;
y1 = floor(path_get_point_y(argument0,i) / argument2) * argument2 + argument2 / 2;
s1 = path_get_point_speed(argument0,i);
path_change_point(argument0,i,x1,y1,s1);
}
return 1;
}Enjoy,
-DF81