Note: the GUI 'layer' isn't a real layer, it's just easier to refer to it that way. Instances would be on the same layers they always are its just that the gui draw events happen after all prior draw events and with their own resolution.
Thank you! For those who were a bit confused like me, I was confused because I thought that by manually placing the object carrying the GUI code in one spot, it would prevent me from interacting with it if I moved to a different location in my game map because the object itself would be located in another area while the GUI stays on one spot in the layer. Luckily this is not the case, as you can interact with the new GUI button from any point in the room after moving! Thanks for the tutorial!
Fantastic tutorial! But if you've got multiple rooms, having to add the buttons every time in every room doesn't seem to practical. Would there be any way to go around this?
For small games (e.g. gamejams) I actually do just put them in every room, but for larger projects I generally have an initializing room before gameplay where I create objects that need to be persistent across multiple rooms but, for example, shouldn't be in the main menu. I would then have these buttons be marked as persistent and generally a child of some parent so that when you do something like go to a menu where they shouldn't show up you can either deactivate or destroy them. Another option would be to use placing them in the room merely as visual guide. You could then make note of their position and create them through code. For a similar but slightly different approach you could see this video: ua-cam.com/video/RbBgE3cUShc/v-deo.html
I'm not sure what "inside the GUI" means in this case. But to take a guess, you don't create anything inside the gui, you just create an instance of an object (by placing it in the room or using instance_create_*) and then use it on the gui layer.
It depends on how you want to interact with it. An instance's x and y are just numbers, but GameMaker does use them for certain things by default. For example, draw self uses them and the sprites origin point to determine where to draw the sprite. If draw self is used in the draw event, it will be drawn using the room's coordinates. If draw self is used in the draw gui event it will drawn using the gui's coordinates. GameMaker also uses the x and y and any mask assigned to the object determine things like collision or position meeting. The built in events that rely on a mask all use the x/y position in the room, that's why I'm using the step event and checking for a position based on the mouse's gui position.
My player object uses mouse_x and mouse_y to move around, when I applied this code the button is completely unresponsive. I was able to change the size of the GUI layer but there's no response from the button object...
I watch this tutorial over and over again and I can't get the button to show the message. I'm not sure what I'm doing wrong, I set my GUI to the same resolution as my game. It's right there in the middle of the screen, click it, no response.
I'd be happy to look at it. A couple questions: - which version of GM (2.2, 2.3, etc.) are you using? - What device (windows, mac, android, etc.) are you testing on? - Even though it seems redundant, can you post both your code and the events the code is in?
@@SamSpadeGameDev In my haste, before setting the GUI size, I changed position_meeting to place_meeting. After I set the size of the GUI, place_meeting was not effective and I forgot to change it back! Once I set it back to position_meeting it worked... hehe. In case anyone else has this issue (doubtful) !!! HA. Thank you for your time and tutorial
Hi, My Wish is to show the GUI as a journal to write in. Like an inventory. its there on the key presses trigger, but now Always, i struggle to do that :(
Great tutorial and helper me a lot but u mispronounced GUI every time lol. It’s pronounced (gee-you-eye) in case u were wondering. But other than that amazing tutorial!!!
Thanks! GUI actually has two valid pronunciations (Gee-you-eye and Gooey) and it might depend on regions as to which is more common. Gooey is the more common pronunciation were I'm at.
Note: the GUI 'layer' isn't a real layer, it's just easier to refer to it that way. Instances would be on the same layers they always are its just that the gui draw events happen after all prior draw events and with their own resolution.
4 years later, this little trick is still working
Thank you so much
As an amateur you have saved me. I was overthinking this and you couldn't have explained it better! Keep up the videos!
Thank you! For those who were a bit confused like me, I was confused because I thought that by manually placing the object carrying the GUI code in one spot, it would prevent me from interacting with it if I moved to a different location in my game map because the object itself would be located in another area while the GUI stays on one spot in the layer. Luckily this is not the case, as you can interact with the new GUI button from any point in the room after moving! Thanks for the tutorial!
Man I love you no homo I watched tons of videos and read a lot of guides but none of them worked and they were all so complicated.
Dang it, I've figured out this trick myself and wanted to make a tutorial LoL
Good job!
Thanks to this video, I were able to implement GUI buttons on the actual Android device! Thank you so much!
love your tutorials, everything s so well explained and planned step by step, gonna get big soon enough!
Classic vid, how did I miss this one? UI buttons are a lot more fun now that we have nine slice for our sprites. 😃
You explained it so perfectly, thank you very much!
really simple explanation, thanks
How frustrating it was to create a basic UI and then figure out it is completely broken if I move my viewport. But now I know what to do. Thanks!
thank you, love youre videos
Fantastic tutorial! But if you've got multiple rooms, having to add the buttons every time in every room doesn't seem to practical. Would there be any way to go around this?
For small games (e.g. gamejams) I actually do just put them in every room, but for larger projects I generally have an initializing room before gameplay where I create objects that need to be persistent across multiple rooms but, for example, shouldn't be in the main menu. I would then have these buttons be marked as persistent and generally a child of some parent so that when you do something like go to a menu where they shouldn't show up you can either deactivate or destroy them.
Another option would be to use placing them in the room merely as visual guide. You could then make note of their position and create them through code.
For a similar but slightly different approach you could see this video: ua-cam.com/video/RbBgE3cUShc/v-deo.html
@@SamSpadeGameDev Thanks a bunch, this actually makes sense! Definitely going to check that video out, cheers :)
But how can I create objects "inside the GUI" with code?
I'm not sure what "inside the GUI" means in this case. But to take a guess, you don't create anything inside the gui, you just create an instance of an object (by placing it in the room or using instance_create_*) and then use it on the gui layer.
@@SamSpadeGameDev Yeah, I'm talking about instance_create. What kind of coordinates should you use? Room coordinates?
It depends on how you want to interact with it. An instance's x and y are just numbers, but GameMaker does use them for certain things by default. For example, draw self uses them and the sprites origin point to determine where to draw the sprite. If draw self is used in the draw event, it will be drawn using the room's coordinates. If draw self is used in the draw gui event it will drawn using the gui's coordinates. GameMaker also uses the x and y and any mask assigned to the object determine things like collision or position meeting. The built in events that rely on a mask all use the x/y position in the room, that's why I'm using the step event and checking for a position based on the mouse's gui position.
thanks, help me a lot.
My player object uses mouse_x and mouse_y to move around, when I applied this code the button is completely unresponsive. I was able to change the size of the GUI layer but there's no response from the button object...
I watch this tutorial over and over again and I can't get the button to show the message. I'm not sure what I'm doing wrong, I set my GUI to the same resolution as my game. It's right there in the middle of the screen, click it, no response.
I'd be happy to look at it. A couple questions:
- which version of GM (2.2, 2.3, etc.) are you using?
- What device (windows, mac, android, etc.) are you testing on?
- Even though it seems redundant, can you post both your code and the events the code is in?
@@SamSpadeGameDev In my haste, before setting the GUI size, I changed position_meeting to place_meeting. After I set the size of the GUI, place_meeting was not effective and I forgot to change it back! Once I set it back to position_meeting it worked... hehe. In case anyone else has this issue (doubtful) !!! HA. Thank you for your time and tutorial
Is this the best way for gui buttons that keep proportions and position on mobile devices and computers.
Thanks man!
Hi,
My Wish is to show the GUI as a journal to write in. Like an inventory. its there on the key presses trigger, but now Always, i struggle to do that :(
Well, i figured it out. But very much needed the video for the rest, thanks a lot :)
Life saver!
how do I hide the text at the top?
I'm not sure what you mean. Text at the top of UA-cam? GameMaker? Your own game? I might need a little more detail here.
@@SamSpadeGameDev the X and Y of the mouse and stuff
I did what you did. I have no idea what i did. But its doing the did
Become my teacher
Great tutorial and helper me a lot but u mispronounced GUI every time lol. It’s pronounced (gee-you-eye) in case u were wondering. But other than that amazing tutorial!!!
Thanks! GUI actually has two valid pronunciations (Gee-you-eye and Gooey) and it might depend on regions as to which is more common. Gooey is the more common pronunciation were I'm at.
SamSpadeGameDev ok that’s fair. Still thanks a lot