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

Interface Buttons with zooming [SOLVED]

D

Diogo

Guest
Hello, there!

I'm trying to create an interface with buttons, while allowing zooming in the room, but having the buttons stay on the same position on screen.

The drawing part is easy, using the GUI function. The collision (for clicking), however, doesn't work, because the object stays in the same position in the room when I zoom in/out.

Is there a way of getting an object's coordinates on the screen? Or do I have to calculate them, and scale everything by hand?

P.S.: I'm aware of window_get_mouse_x(), but I think I still need the objects version of that.

Thanks!
 

Tthecreator

Your Creator!
The coordinates when using the "draw GUI event" (which is what I'm guessing you're using), are independent of the object's coordinates.
What code do you use for drawing the buttons?
If you have some fixed coordinates, you can just do a point_in_rectangle(), using window_get_mouse_x() and the coordinates of your button.
It really depends on what code you are using to draw your buttons.
 
D

Diogo

Guest
I'm simply drawing the sprite (draw_self()), centered on the object's (x, y) coordinates in the room. (I've positioned them in the room at their right spot, initially). Does that make any sense?
It's a slider, so it moves around a bit.

I'm using the sprite as a collision mask, but point_in_rectangle works just the same.

I was placing things in the room, instead of placing them relative to the screen, which was a bad approach to begin with, I suppose.
 

Tthecreator

Your Creator!
I get what and how you are trying to do this. Though an easier methods would be getting the 4 coordinates using:
Code:
x1=x;//top left
y1=y;//top left
x2=x+sprite_get_width(spr_whatever)//bottom right
y2=y+sprite_get_height(spr_whatever)//bottom right
Then using these values to calculate a point_in_rectangle, using the window_get_mouse_ functions.
 
D

Diogo

Guest
Still doesn't detect the collision, after I've changed the zoom. Trying to use view_xview[0] doesn't help either.

Either way, I appreciate your help! :) I'll keep digging.


EDIT: I'm sorry, the problem was an entirely different thing, haha!
When updating the slider's position, I was using mouse_x, instead of window_mouse_get_x() ... as a result, when the collision was detected, the slider still wouldn't move, because I was giving it the wrong position.


The way you described works completely fine, thank you very much! :)
 
Last edited by a moderator:
Top