• 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 [Solved] Get an object's coordinates on the GUI layer

I have a chest object in my game that shows what is in it when you click on it. The problem is that I want the inventory to be drawn on the GUI layer but still next to the chest. The issue is, I don't know how to find out where on the GUI layer the chest would be.
Any help is appreciated! ;)
 
P

PandaPenguin

Guest
substract your views x/y from your chest objects x/y
the GUI layers x/y starts with 0,0 where your views x/y is

I use this methode in my own game to show object "popup" name tags on the GUI layer when you mouse-over objects on the regular layer (application_surface)
 
substract your views x/y from your chest objects x/y
the GUI layers x/y starts with 0,0 where your views x/y is

I use this methode in my own game to show object "popup" name tags on the GUI layer when you mouse-over objects on the regular layer (application_surface)
This doesn't seem to work for me,
I created two scripts (just to make it easier for me to do)
XtoGUI:
Code:
///XtoGUI(x)
return(argument0-view_xview)
YtoGUI:
Code:
///YtoGUI(y)
return(argument0-view_yview)
and I created this in the draw event to test it:
Code:
draw_text(XtoGUI(x),YtoGUI(y),"Test")
but it isn't centered on the x and y. It seems to move slightly in the opposite direction as I move the view_xview and view_yview.
 
P

PandaPenguin

Guest
This doesn't seem to work for me,
I created two scripts (just to make it easier for me to do)
XtoGUI:
Code:
///XtoGUI(x)
return(argument0-view_xview)
YtoGUI:
Code:
///YtoGUI(y)
return(argument0-view_yview)
and I created this in the draw event to test it:
Code:
draw_text(XtoGUI(x),YtoGUI(y),"Test")
but it isn't centered on the x and y. It seems to move slightly in the opposite direction as I move the view_xview and view_yview.
sorry I forgot to add that this works if your view_port and window aspect ratio are the same, if any of these two is different you need to calculate for this offset too
 

jo-thijs

Member
I have a chest object in my game that shows what is in it when you click on it. The problem is that I want the inventory to be drawn on the GUI layer but still next to the chest. The issue is, I don't know how to find out where on the GUI layer the chest would be.
Any help is appreciated! ;)
That's not really what the GUI draw event is for, but ok.

This doesn't seem to work for me,
I created two scripts (just to make it easier for me to do)
XtoGUI:
Code:
///XtoGUI(x)
return(argument0-view_xview)
YtoGUI:
Code:
///YtoGUI(y)
return(argument0-view_yview)
and I created this in the draw event to test it:
Code:
draw_text(XtoGUI(x),YtoGUI(y),"Test")
but it isn't centered on the x and y. It seems to move slightly in the opposite direction as I move the view_xview and view_yview.
It actually depends on a lot of factors.
It depends on whatever you've used display_set_gui_maximise,
on whatever you're using views, how many views there are (with multiple views, there might be multiple results or none at all),
on the x and y of the views, the width and height of the views, the x and y of the ports, the width and height of the ports,
window dimensions, fullscreen, ...

Generally speaking though, you should be able to just do this:
Code:
///XtoGUI(x)

var t = application_get_position();
return (argument0 - view_xview) / view_wview * (t[2] - t[0]);
 
  • Like
Reactions: Rob
That's not really what the GUI draw event is for, but ok.


It actually depends on a lot of factors.
It depends on whatever you've used display_set_gui_maximise,
on whatever you're using views, how many views there are (with multiple views, there might be multiple results or none at all),
on the x and y of the views, the width and height of the views, the x and y of the ports, the width and height of the ports,
window dimensions, fullscreen, ...

Generally speaking though, you should be able to just do this:
Code:
///XtoGUI(x)

var t = application_get_position();
return (argument0 - view_xview) / view_wview * (t[2] - t[0]);
ok this works, thanks!
 
Top