With this function you can check a position for a collision with another instance or all instances of an object.
In addition to objects and instances, the function also accepts:
Passing an array allows you to check for collisions against multiple objects and/or Tile Maps in one call.
When you use this, you are checking a single point in the room for instances or tile maps. 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.
This function will return the ID of the instance or tile map that is first found in collision. If nothing is found, noone is returned.
If you do not need the id of the colliding instance you should consider using position_meeting() instead.
See: Collisions
instance_position(x, y, obj);
Argument | Type | Description |
---|---|---|
x | Real | The x position to check for instances. |
y | Real | The y position to check for instances. |
obj | Object Asset or Object Instance or Tile Map Element ID or Array | An object, instance, tile map ID, keywords all/other, or array containing these items |
Object Instance or Tile Map Element ID or noone
var inst;
inst = instance_position(mouse_x, mouse_y, obj_Pause_Button);
if (inst != noone)
{
with (inst) image_index=1;
instance_create_layer(room_width / 2, 0, "Controllers", 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".