How to Create a gui layer?

Hello every one!! I'm trying to create a GUI layer but I didn't find any tutorial or documentation easy to understand for begginers, I watched a few times the video of @Pixelated_Pope where he explain for more advanced user how to implement a GUI layer where you can change your aspect ratios, I tried to follow that tutorial but at some point i don't know how proceed.
1611742529245.png 1611742580589.png
this is one of the levels of my game, when the lives counter reach 0 i want this to appear: a GUI layer with some clickable buttons like restart game, go to main menu...

I have tryed to reuse some parts of the code but for me at this point is a bit complicated, Does anyone knows how can i make this gui layer a real thing? thanks :)
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
GUI layers aren't created in the game... there is just ONE gui layer, and it exists from the moment your game starts. To target it, you simply set it's size (using display_set_gui_size() ), and then all instances that you want on the GUI layer should have a comment in their DRAW event and the actual code for drawing in the DRAW GUI event. Why the comment? So, GMS will "default draw" any sprite assigned to the instance in the Draw Event (even if the event isn't shown in the object), so by adding a single comment to this event it tells GMS not to draw anything, and so all your instances with a commented Draw Event and code in the Draw GUI event will automatically draw to the GUI layer.

Also, if you are wanting user input from items on the GUI layer you need to convert the mouse room coordinates into GUI layer coordinates. This is done quite easily by using the function device_mouse_x_to_gui and the function device_mouse_y_to_gui. :)

Some links to help you along...

 
GUI layers aren't created in the game... there is just ONE gui layer, and it exists from the moment your game starts. To target it, you simply set it's size (using display_set_gui_size() ), and then all instances that you want on the GUI layer should have a comment in their DRAW event and the actual code for drawing in the DRAW GUI event. Why the comment? So, GMS will "default draw" any sprite assigned to the instance in the Draw Event (even if the event isn't shown in the object), so by adding a single comment to this event it tells GMS not to draw anything, and so all your instances with a commented Draw Event and code in the Draw GUI event will automatically draw to the GUI layer.

Also, if you are wanting user input from items on the GUI layer you need to convert the mouse room coordinates into GUI layer coordinates. This is done quite easily by using the function device_mouse_x_to_gui and the function device_mouse_y_to_gui. :)

Some links to help you along...

thank you very much for your help!! I will check all the documentation :D
 
Top