point_in_rectangle

When using this function, you define a rectangular area and GameMaker will work out whether the given point falls within its bounds or not. If the point falls within the defined rectangle the function will return true otherwise the function will return false.

 

Syntax:

point_in_rectangle(px, py, x1, y1, x2, y2);

ArgumentType Description
pxReal The x coordinate of the point to check.
pyReal The y coordinate of the point to check.
x1Real The x coordinate of the left side of the rectangle to check.
y1Real The y coordinate of the top side of the rectangle to check.
x2Real The x coordinate of the right side of the rectangle to check.
y2Real The y coordinate of the bottom side of the rectangle to check.

 

Returns:

Boolean

 

Example:

if point_in_rectangle(mouse_x, mouse_y, x -10, y - 10, x + 10, y + 10)
{
    audio_play_sound(snd_click, 0, false);
}

This short code checks the mouse position against the defined rectangular area and plays a sound if it falls within the bounds.