• 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 how to check if object is inside the view? [SOLVED]

F

fxokz

Guest
Basically what the title says. I want to be able to make a script that checks whether an object is visible inside the view but am not quite sure how to go about it. Does anybody have any advice? I havent been programming at all for the past 3 weeks so my brain isnt fully functioning. :S
 

GMWolf

aka fel666
Use point_in_rectangle().

Code:
if (point_in_rectangle(x, y, view_xview[0], view_yview[0], view_xview[0] + view_wview[0], view_yview[0] + view_hview[0])) {
   // Do something
}
Problem with this technique is that if the origin of the object is just outside the view, it will still return false even if part of the object in in view.

Remember you have bbox_* to help you!
Code:
if ((bbox_right > view_xview[0]) && (bbox_left < view_xview[0] + view_wview[0]) && (bbox_bottom > view_yview[0]) && (bbox_top < view_yview[0] + view_hview[0])) {
   //Do your stuff
}
 
Top