• 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!

(Solved) GUI object offset when zooming view

T

tugalaw

Guest
Hi,

I'm somewhat new to GMS and I've been making some experiments.

One of them is using Draw GUI to display an interface that you can interact with - clicking buttons, opening menus, etc.

I've also added camera zoom to the mix, and that's where I'm having problems.

When zooming the view in and out, the GUI is perfectly displayed at its correct scale and position in the camera.

But the actual GUI objects (their collisions perhaps) are affected by the zoom.

Those objects have a mouse over effect and I can tell where the "real object" is in the room by moving the mouse around, and it doesn't match what I see in the GUI (i.e.: there's a button in the top left corner, and the mouse over is detected in the middle of the screen).

For two days I've tried a bunch of ways to solve the offset, but I'm nowhere close to a solution.

Help?
 

Stubbjax

Member
The traditional way to do it is to simply position your objects (or do the mouse checking, if they aren't objects) in relation to the scale of the view.

This usually involves repositioning and scaling your GUI elements manually, like this:
Code:
button.x = view_xview + (view_wview / 2);
button.y = view_yview + view_hview - 20;

button.image_xscale = 1 / your_zoom_value;
button.image_yscale = 1 / your_zoom_value;
Hope that helps!
 

MusNik

Member
You can try to use device_mouse_x_to_gui or similar instead of just mouse_x when checking mouse overlap.
 
T

tugalaw

Guest
You can try to use device_mouse_x_to_gui or similar instead of just mouse_x when checking mouse overlap.
So simple... Didn't know of this function. Thank you, it worked!

@Stubbjax: This is also good to know, I'll take note. Thanks!
 
F

flaame1979

Guest
I think this may help me too!
I've been using keyboard commands as a stop-gap measure because I couldn't figure how to use GUI Buttons with a mouse.
 
T

Tyler Ratliff

Guest
Just learned about this while working on an inventory system. :) Got everything down now except dropping items from the inventory into the game world.

Such a useful function!
 
Top