GM: instance position

From GMpedia.org Wiki

Jump to: navigation, search
The correct title of this article is instance_position(x,y,obj). It appears incorrectly here because of technical restrictions.
The correct title of this article is instance_position(). It appears incorrectly here because of technical restrictions.


Arguments

x = Horizontal position of the point we're checking. y = Vertical position of the point we're checking. obj = The object we're checking if is there.

Limitations

none

Note: Please remove limitations and port them in the "Remarks" section at the end of the article.

The instance_position() function returns the id of the instance of an object (obj) at a particular position (x,y).

[edit] Explanation

What does "position" mean? Position is a point in the room with the same size as a pixel. If you check for instances at a position the size of the sprite of the object that does the check doesn't matter. Only the sprite of the object that is searched for matters.

//the following will usually return false because the position
//where the check is made is at the top of the sprite+1 and not
//under the sprite.
//To make this return true you could make the y-origin of the
//sprite the height of the sprite -1.
//Why -1? Because the 0 is at the top, not 1.
amIStandingOnSomething = instance_position(x,y+1,obj_ground);
if(amIStandingOnSomething==false) y+=1

[edit] See Also

This article was originally found at the Game Maker Knowledge Base, contributed by SpectreNectar.
See the talk page for details
Personal tools