instance_position

Checks for a collision with the specified object at a specific location and returns its id.

Syntax:

instance_position( x, y, obj );


Argument Description
x The x position to check for instances.
y The y position to check for instances.
obj The object to check for instances of.


Returns: Real


Description

With this function you can check a position for a collision with another instance or all instances of an object. When you use this you are checking a single point in the room for an instance or an object. This check will be done against the bounding box of the instance or against the mask of the instance if that instance has precise collisions checked and will return the unique instance id. If you do not need the id of the colliding instance you should consider using position_meeting instead. This function also accepts the special keywords all and other and will return the keyword noone if no collision occurs.


Example:

var inst;
inst = instance_position(mouse_x, mouse_y, obj_Pause_Button);
if inst != noone
   {
   with (inst) image_index=1;
   instance_create(room_width / 2, 0, obj_Menu);
   }

The above code will check for a collision with an instance of "obj_Pause_Button" at the mouse position, and if there is one it will then use the returned id to set its image_index to a new value before creating a new instance of the object "obj_Menu".


Back: Instance Functions
© Copyright YoYo Games Ltd. 2018 All Rights Reserved