• 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 Get center of every children of Parent_Enemy instance

Axl Trauts

Member
Hi,

I have a top down shooter and I have this special gun that shoots sticky bombs from above. The should appear at the middle of every enemy instance using its parent par_Enemy.
Each enemy has different origins due to their unique behaviors, so using something like this on the script that fires the sticky bomb, it won't appear on the center of every instance but the ones with 0,0:

GML:
    if !instance_exists(obj_stickybomb)
    {    with(par_Enemy)
        {    if enemy_type="ALL"    // not relevant now
            {    instance_create_depth(x+sprite_width/2,y+sprite_height/2,par_Enemy.depth-1,obj_stickybomb);
            }
        }
    }
I don't want to modify permanently all their origins with sprite_set_offset. If there's no way, I'll have to figure out a different effect.
 

TheouAegis

Member
bbox_left+bbox_right>>1
And
bbox_top+bbox_bottom>>1

That's for center of bounding box.

Otherwise you will need to subtract sprite_xoffset and sprite_yoffset from x and y then add half-width and half-height.
 
Top