• 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!

GameMaker Getting height of sprite without using precise collisions?

JasonTomLee

Member
Hey GM community, was wondering how I could get the height of a sprite ( with or without precise collisions ).
The Red box represents the Mask of the player object, so the position is offset by the collided object's height.

Any methods you'd suggest?
This is what I have but doesn't work with precise collisions:
Code:
if ( place_meeting( x,y, _obj )){
    var _yoff = 0;
    while( collision_point( x,y+ _yoff, _obj, true, true )){
        _yoff--;
    }
    yoff = _yoff;
}else{
    yoff = 0;
}
 

Attachments

CloseRange

Member
It's possible that it's not working because you're using collision point. The point starts at the objects origin so unless the origin of the object is the bottom center, the point you are checking could start in the wrong place.
You could change collision point to use place meeting or calculate the bottom middle of the player object (or the bottom of the collision object) and start off the while loop there.

In terms of optimization using brute force like this will take order h where h is the height of the sprite. that's not bad but technically it could be better.
 
Top