Legacy GM Question regarding button using Draw GUI

N

Navimaster

Guest
This is my button drawn under the Draw GUI event.



Fairly simple. It draws a rectangle and the text "New Game" on it. When the mouse hovers over it, it lights up. When you click it, the graphic changes. It's a good button.




The problem occurs when I enter the area of the button while HOLDING the mouse button down.




See how it behaves? Instead of lighting up, it gets pressed.

All because I am holding the mouse button as I come in. Any way to avoid this and have it light up instead?
 
Last edited by a moderator:

jazzzar

Member
Code:
If (distance_to_point(mouse_x,mouse_y)<=0)
{
    If mouse_check_button(mb_left)
    draw_sprite(blahblahblah)
}
Hope it helps
 
N

Navimaster

Guest
Sorry, I don't understand your answer.

It's a drawn button. It's reacting to the rectangle coordinate area.
 

RangerX

Member
You are using "mouse check button". Isn't there a "mouse check button pressed" or something that is available? (i'd have to check, I am not near my GMS)
 
N

Navimaster

Guest
I tried the mouse_check_button_pressed approach... and it immediately lights it back up after I click.

Any other suggestions?

Also, the "mouse check button" behaves the way I want it to for the most part. If you hold the button down, it stays down.

The problem is not what the button does when my mouse is on top of it. The problem is what happens when I'm holding the mouse down as I approach the button.

Let me illustrate..

<-- Holding down the mouse button while on top of it? Fine.



<-- Holding down the mouse button as I approach it? Not fine. X
 

GMWolf

aka fel666
unfortunately this will not be possible without states.
You can store variables like 'clicked', 'hovered' and all, but this can get a little messy.
I would recomend you implement it as a state machine. (Check out my tutorial here:
Sorry, couldnt just paste a link without GMC wanting to embed the video as media
).
I would have a neutral state, a hovered state and then a cliked state.
from the neutral state you can go to the hover state by hovering on the button.
from the hover state you can go back to the neutral state by removing the mouse or the clicked state by clicking the button.
from the cliked state you can go the the hover by releasing in the button, or neutrl state by releasing outised the button.

Hope this helps!
 
N

Navimaster

Guest
Interesting... I've never heard of them. I'll check out your tutorial and hopefully apply a working system to my buttons. Very helpful, thank you!
 

GMWolf

aka fel666
My i also point out it is extremely bad form to avoid objects and use magic numbers like you are doing!
i strongly advise you use a separate object for each button! (if you want to move a button around now, you have tons of number to change D:)
 
N

Navimaster

Guest
Oh, hmm... so I shouldn't use Draw GUI to draw my UI? I guess I could, but like you said, it might be harder later on to do more complex things without objects.

Alright then, I'll use objects for my buttons from now on. Thank you for the tips.
 

GMWolf

aka fel666
Oh, hmm... so I shouldn't use Draw GUI to draw my UI? I guess I could, but like you said, it might be harder later on to do more complex things without objects.

Alright then, I'll use objects for my buttons from now on. Thank you for the tips.
Create a button object, but have it be drawn in the draw gui event of that button.
 
Z

Zachari

Guest
Hello, I'm trying to solve another issue with my buttons/GUI and i found this thread, I just have a question...
Create a button object, but have it be drawn in the draw gui event of that button.
If i do this, the button doesn't react to mouse inputs because its actual coordinates don't correspond to where the gui is, How can you line your button up with the gui button?
 

GMWolf

aka fel666
Hello, I'm trying to solve another issue with my buttons/GUI and i found this thread, I just have a question...

If i do this, the button doesn't react to mouse inputs because its actual coordinates don't correspond to where the gui is, How can you line your button up with the gui button?
rather than the mouse pressed events, do the check in the step event using device_mouse_x_to_gui and device_mouse_y_to_gui
 
W

WoohooDaThird

Guest
I know this thread is old but you can use the mouse_check_button_pressed(<button>) to check if a button was pressed. This means someone will have to hold down the button then release instead of just holding it down.
 
Top