When you define a sprite in the sprite editor, you need to set the origin for that sprite. This is the point at which the sprite will be "attached" or "drawn" when used with an instance. This function returns the relative offset for the y-axis of the origin based on the upper left corner being the 0,0 position, with a +y being down and a -y being up from this. The following image illustrates this:
|index||The index of the sprite to find the yoffset of.|
if y - sprite_get_yoffset(sprite_index) < 0
y = sprite_get_yoffset(sprite_index);
The above code will ensure that an instance is maintained within the room based on the sprite (so the sprite is always visible).