The Draw GUI Event

The Draw GUI Events are some of the many events that can be triggered in an instance and may contain code or actions.

Draw GUI Event
The Draw Gui event type falls under the Draw Event category and are specifically designed for drawing GUI (Graphical User Interface) elements that are not affected by the view scale or rotation. This means that you can have an instance draw all the elements for your HUD without having to base all the positioning on the position within the room of the instance and the position of the current view either.

When drawing in these event it is important that you understand that the draw coordinates do not change even when views are active and 0,0 is always the top left hand corner of either the application surface or the display (see the note at the bottom of this section), and the default width and height are 1:1 with the application surface. Depth ordering is still maintained between different instances (so an instance at a low depth will draw over one at a higher depth) and also within the events themselves, as the Draw GUI Begin event will draw for all instances first, then the standard Draw GUI will draw for all instances over that, and finally the Draw Gui End event is triggered.

In this way, you can draw things or set draw properties in the Draw GUI Begin step in one instance and be sure that all instances with a standard Draw GUI event or Draw GUI End event will use these properties or draw over what the first instance has drawn. Basically its a sure fire way to guarantee that certain things are drawn at certain times, much like the Begin Step and End Step events do.

These events can also be used in conjunction with the normal Draw events (which will be affected by the view position, scale and rotation as normal). If you have no Draw Event but you do have a Draw GUI Event, then GameMaker: Studio will still default draw the sprite for the instance (if it has one) as normal.

You may notice depth issues when using this event due to the fact that it is not dealt with the same was as the traditional draw event. What happens is that the normal draw events for all instances are resolved first, once each for each active view, and then the draw GUI events for all instances are resolved. So the depth order between instances with draw GUI events is always respected, as is the depth order between instances with normal draw events, but the draw GUI events will always draw over anything drawn in the normal draw event, even if the instance doing the drawing it is at a higher depth than other instances.

NOTE: This event will, by default, draw 1:1 with the application surface size, which is normally the size of the room or the view port. This means that when you have Aspect Ratio Correction on in the Global Game Settings the GUI is not going to be drawn over the black bars that "letterbox" the game. This behaviour can be switched off using the display_set_gui_maximise function, and you can also lock the GUI event to a specific size which will then be scaled to fit the display or application surface dimensions automatically by using the function display_set_gui_size.


Back: Events
Next: The Pre And Post Draw Events
© Copyright YoYo Games Ltd. 2018 All Rights Reserved