• Hey! Guest! The 37th GMC Jam will take place between May 28th, 12:00 UTC and June 1st, 12:00 UTC. Why not join in! Click here to find out more!

Drag And Drop Check if object is in viewport ?

Antera

Member
Hello,

How can I check if the instance of an object is in viewport, is there a function for this ?

Or do I have to add multiple DND "if" to reproduce something like this ?

if ( (x > view_xview[0]) && (y > view_yview[0]) && (x < (view_xview[0]+view_wview[0])) && (y < (view_yview[0]+view_hview[0])) )

I use Drag & Drop fow now

Thanks for your help
 

Attachments

TheouAegis

Member
///is_inview(id)
with argument0 return (x > view_xview[0]) && (y > view_yview[0]) && (x < view_xview[0]+view_wview[0]) && (y < view_yview[0]+view_hview[0]);


You'd call it with one argument, like
if is_inview(nearest_enemy)
 
Last edited:

FrostyCat

Member
Thanks TheouAegis
Why is there a warning to view_wview ?
That's because view_wview[0] and the rest of the lot are obsolete. Use the Camera Getters listed on this page with view_camera[0].

If you're new and you're learning GMS 2, using GMS 1.4 resources is one of the most unwise things you can do.
 

Antera

Member
That's because view_wview[0] and the rest of the lot are obsolete. Use the Camera Getters listed on this page with view_camera[0].

If you're new and you're learning GMS 2, using GMS 1.4 resources is one of the most unwise things you can do.
Thanks. This code was given here just above. It's working now :)
 

Antera

Member
In fact it's not working, still on it :-(
it returns 0 sometimes, even the object is in view

var view_x = camera_get_view_x(view_camera[0]);
var view_y = camera_get_view_y(view_camera[0]);
var view_w = display_get_gui_width();
var view_h = display_get_gui_height();
var reponse = (x > view_x) && (y > view_y) && (x < view_x+view_w) && (y < view_y+view_h);
return reponse;
 
The GUI and the camera are separate, you shouldn't be trying to compare them in this context. This is what you should be checking instead.
Code:
var view_x = camera_get_view_x(view_camera[0]);
var view_y = camera_get_view_y(view_camera[0]);
var view_w = camera_get_view_width(view_camera[0]);
var view_h = camera_get_view_height(view_camera[0]);
 

Antera

Member
Yes got it
var view_x = camera_get_view_x(view_camera[0]);
var view_y = camera_get_view_y(view_camera[0]);
var view_w = camera_get_view_width(view_camera[0]);
var view_h = camera_get_view_height(view_camera[0]);
 
Top