point_in_rectangle


描述

When using this function, you define a rectangular area and GameMaker Studio 2 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.


语法:

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

参数 描述
px The x coordinate of the point to check.
py The y coordinate of the point to check.
x1 The x coordinate of the left side of the rectangle to check.
y1 The y coordinate of the top side of the rectangle to check.
x2 The x coordinate of the right side of the rectangle to check.
y2 The y coordinate of the bottom side of the rectangle to check.


Returns:

Boolean


例如:

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.