• 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]Best way to create a GUI button that DOESN'T interact with the room at the same time?

yukaccino

Member
Hello!
Probably the title sounds a bit confusing, I'm sorry. My trouble isn't with a specific code bugging, it's more like a logic problem that I'm struggling a bit. I'm sorry if this isn't the correct forum to post, but I don't think this fits in Game Design.

Right at the moment, if my mouse is over my GUI button, and below in the room is a character, the moment I click with my mouse both the button and the character will be selected.
Any tips on how to code it to not interact with instances in the room, when my mouse is over a certain region of the display?

1634640048590.png
Sorry for the mess here, I'm still remaking my HUD!

Not sure if it's worth mentioning, but all my GUI is drawn in a same Draw GUI event in the same object. I thought it was easier for me to do this.

Thanks!
 
Last edited:

yukaccino

Member
When over gui elements set a variable to true ( set it to false before checking any gui elements), in the other objects, don't do anything if it is true.. could keep it global.

Edit: "Set a flag" is the term they use for it
Yeah, I've thought about that as well, but I wasn't sure if it was the most effective way and I was hoping there was another solution since I should've thought about that way earlier. My game has a lot of different objects right now with different parents... That's why I asked if there was a way, perhaps some kind of funciton that I didn't knew about, that could make a region in the screen only available for the GUI.
Now that I think about it, perhaps it would be to create a different viewport and just make a part of the display not showing anything, but that may be as troublesome as setting a flag, wouldn't? :/
 

TailBit

Member
You can also use mouse_clear and make sure that the gui object is high on the room instance list (unless you create it before entering the room)

That way it can clear the press before any other triggers it
 

gnysek

Member
Step begin/end are good places to put code for interacting with gui and then lock normal step event interaction with mouse. Example:

GML:
/// begin step
locked = false;
if (device_mouse_y_to_gui(0) <= 50) locked = true; // where 50 is top bar height


/// normal step

if not locked {
   ... /// normal mouse interaction here
}
 

yukaccino

Member
Seems like it's the best way indeed to just lock my step event. I wish I had thought about that earlier tho :/
Anyway, thanks for the help!
 
Top