Fandom

Game Maker

Collision rectangle

281pages on
this wiki
Add New Page
Talk0 Share

Checks if the mask of an object collides with a rectangle at given position.


This could be useful when creating text, as buttons.

In this case, you would create a 1x1 sprite, and move it to mouse_x, and mouse_y each step.


In your button, you would then type:

if collision_rectangle(x-string_width(text)/2,y-string_height(text)/2,x+string_width(text)/2,y+string_height(text)/2,obj_mouse,true,false)

{

//Do your thing

}

x1: Upper left corner of the rectangle, pixels from the left side of the window

'y1: 'Upper left corner of the rectangle, pixels from the top of the window

x2: Lower right corner of the rectangle, pixels from the left side of the window

y2: ' Lower right corner of the rectangle', pixels from the top of the window

(for instance, x1 = 0, y1 = 0, x2 = 50, y2 = 50, would make a 50x50 rectangle collision.) 

obj: Object to collide with

prec: Precise collision checking

notme: Not too entirely sure, shame on me. I usually leave that false.

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.