• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM point_in_rectangle not working (FIXED)

Y

Yvalson

Guest
Code:
if(point_in_rectangle(device_mouse_x(0),device_mouse_y(0),view_xview+view_wview/2, view_hview, view_xview+view_wview, view_yview) or point_in_rectangle(device_mouse_x(1),device_mouse_y(1),view_xview+view_wview/2, view_hview, view_xview+view_wview, view_yview)){
if(device_mouse_check_button(0, mb_left)){
    self.x = mouse_x
    self.y = mouse_y
}
if(device_mouse_check_button(1, mb_left)){
    self.x = mouse_x
    self.y = mouse_y
}
}
x = clamp(x, Obj_OuterRing_Aim.x - 96, Obj_OuterRing_Aim.x + 96);
y = clamp(y, Obj_OuterRing_Aim.y - 96, Obj_OuterRing_Aim.y + 96);
and second stick
Code:
if(point_in_rectangle(device_mouse_x(0),device_mouse_y(0), view_xview, view_hview, view_xview+view_wview/2, view_yview) or point_in_rectangle(device_mouse_x(1),device_mouse_y(1), view_xview, view_hview, view_xview+view_wview/2, view_yview)){
if(device_mouse_check_button(0, mb_left)){
    self.x = mouse_x
    self.y = mouse_y
}
else if(device_mouse_check_button(1, mb_left)){
    self.x = mouse_x
    self.y = mouse_y
}
}
x = clamp(x, Obj_OuterRing_Move.x - 96, Obj_OuterRing_Move.x + 96);
y = clamp(y, Obj_OuterRing_Move.y - 96, Obj_OuterRing_Move.y + 96);
when I draw the rectangles with draw_rectangle everything works fine (this is in Draw or Draw GUI event) yet when I try point_in_rectangle (in my project those are in the step event) the arent working does anyone know why? this game is for mobile and i'm trying to get 2 joysticks to work. 1 for aiming and the other one for moving.

so 2 fingers on the screen. I'm trying to assign the touch with the corresponding side of the screen using those point_in_rectangles. hope some one can help
 
If I remember correctly, point_in_rectangle wont work correctly unless the argument order is this:

point_in_rectangle(point_x,point_y,left,top,right,bottom);

I'm assuming you have a horizontally scrolling or stationary view, because otherwise the draw rectangle would not work with the same arguments you used in your point in rectangle function.
 
Y

Yvalson

Guest
If I remember correctly, point_in_rectangle wont work correctly unless the argument order is this:

point_in_rectangle(point_x,point_y,left,top,right,bottom);

I'm assuming you have a horizontally scrolling or stationary view, because otherwise the draw rectangle would not work with the same arguments you used in your point in rectangle function.
my argument order should be okay if im right. and I have a view that follows the player both horizontally as well as vertically.
 
Y

Yvalson

Guest
argument order should be:

point_in_rectangle(device_mouse_x(0),device_mouse_y(0), view_xview, view_yview, view_xview+view_wview/2, view_yview+view_hview)
does point_in_rectangle differ from draw_rectangle? anyway thank you I'll try it out and get back at you

EDIT:
just went back to the documentation and indeed you are right I'm so stupid for missing that. well anyway thanks for the support
 
Last edited by a moderator:
Top