O
ObserverOfSin
Guest
Hey all. nice to meet you.
when monitoring fps_real I notice significant drops in frames with each enemy I create.
can someone please take a look at my code to see if they know of more ways to optimize performance?
I am by no means adept at gml.
when monitoring fps_real I notice significant drops in frames with each enemy I create.
can someone please take a look at my code to see if they know of more ways to optimize performance?
I am by no means adept at gml.
GML:
direction = angle
ii +=1
xx = path_get_point_x(path, pos);
yy = path_get_point_y(path, pos);
mp_grid_clear_all(global.grid); /// add instances of self to grid
with enemyparent_obj
{
if (id != other.id) mp_grid_add_instances(other.grid, id, 0);
}
if ii >= 30 /// every 30 frames update coordanites and set ii to 0
{
if point_distance(x, y, xx, yy) < 8
{
if pos < 2
{
pos += 1
}
else
{
pos = 1
xx = irandom(30)
yy = irandom(30)
}
}
ii = 0
}
if atend = 0
{
i +=1
dir = point_direction(x,y,xx,yy)
angle += median(-2, 2, ((((dir - angle) mod 360) + 540) mod 360) - 180);
mp_potential_step(xx, yy, 1, false);
if ii = 0 and instance_exists(target)
{
mp_grid_path(global.grid,path,x,y,target.x,target.y,true)
}
else
{
xx = irandom(30)
yy = irandom(30)
}
{
if i >= 30 /// every 30 frames check if a new target is in range
{
newtarget = instance_nearest(x,y,friendlyparent_obj)
if distance_to_point(newtarget.x, newtarget.y) < sight
{
target = newtarget
pos =1
i = 0
}
i = 0
}
if distance_to_object(target) < 15
{
atend = 1
sprite_index = second
image_speed = aspeed
}
}
}
if sprite_index = attack and (image_index+image_speed >= image_number)/// inflict damage
{
if instance_exists(target) {target.hitpoints -= damage}
if target.hitpoints <= 0 {with(target)instance_destroy()}
}
if !mp_grid_path(global.grid,path,x,y,target.x,target.y,true) /// Target motheship when target dies
{
xx = irandom(300)
yy = irandom(300)
return false;
}
else
{
sprite_index = main
image_speed = 0.2
target = mothership_obj
pos = 1
atend = 0
return true;
}
if sprite_index = second /////turn when attacking
{
dir = point_direction(x,y,target.x,target.y)
angle += median(-2, 2, ((((dir - angle) mod 360) + 540) mod 360) - 180);
}