The Draw Event in GameMaker: Studio

By Michael Rohde

Use the Draw Event in GameMaker: Studio when you want to display something during the game. The Draw Event does have its own submenu, as shown in this figure.

If you use a Draw Event, GameMaker no longer defaults to the assigned Sprite, and instead you have to tell GameMaker what to draw.

The Draw Event submenu.

The Draw Event submenu.

The different options from the submenu include

  • Draw: The standard Draw Event should be sufficient for most of your needs. The Draw Event enables you to place code or Actions for an Object, and those Actions and code override the default draw, which would be the assigned Sprite.

    This is useful, for example, if you want to replace the assigned Sprite with text to display a message. This Event is called once per View, while the other Draw Events are drawn each step of the game.

    All Objects with an assigned Sprite with Visible toggled on (from the Object Properties window, as shown here) automatically trigger a default Draw Event every step of the game. GameMaker does this for you, which is nice, because you don’t have to assign a Draw Event for each Object with an assigned Sprite to have it appear in the game.

    Select the Visible check box to automatically trigger a default Draw Event.

    Select the Visible check box to automatically trigger a default Draw Event.
  • Draw GUI, Draw GUI Begin, and Draw GUI End: GUI is an acronym for graphical user interface. The GUI is not affected by the View scale or rotation. Instead, the GUI is drawn on a separate layer than, say, the background.

    A Draw GUI Event is great for creating a heads-up display (HUD), which can show a player’s health, ammo, weapon type, a mini map, and so on. As with the other Begin and End Events, the Draw GUI Begin and Draw GUI End Events determine the order of what’s drawn.

  • Draw Begin and Draw End: These two Events do exactly as they say: They make sure that something is drawn in the game either before or after the standard Draw Event. Using these Events is a great way to make sure items are drawn in the order you want them to appear.

    The Draw Begin, Draw, and Draw End Events all run before the Draw GUI Events and between the PreDraw and PostDraw Events. This has significant meaning in that all these Events are drawn beneath the Draw GUI Event, no matter what the Depth is set at.

  • PreDraw and PostDraw: The PreDraw and PostDraw Events are drawn directly to the screen buffer, which is the combined screen space for all Views currently visible, or the window size if you don’t use Views.

    The PreDraw Event is triggered before any other Draw Events, which means you can use it to set values, set draw properties, and, of course, draw things. The PostDraw Event runs after the other Draw Events but before the Draw GUI Event.

    You need to deselect the Clear Background with Window Colour check box in the Room editor for PreDraw and PostDraw Events to work. This figure shows where to deselect this feature (the default setting has it selected). You also need to make sure that a background color is not drawn; you do this on the Background tab.

    Do not select Clear Background with Window Colour for PreDraw and PostDraw Events.

    Do not select Clear Background with Window Colour for PreDraw and PostDraw Events.

    If you turn off the View Clearing and disable drawing a background color, you might experience trails (leftover traces of images) during gameplay. These trails happen because now you’re drawing directly over the previous frame without it being cleared.

    You can use code to help solve this potential problem, which is draw_clear_alpha. You can place this code in an Execute Code Action within the PreDraw or PostDraw Event.

  • Resize: The Resize Event is used specifically for Windows 8 games and doesn’t actually draw anything in the game. Instead, the Resize Event is to help snap the game window when the player moves that window to the side of the screen.

    If you’re familiar with working in a Microsoft Windows environment, you’re aware that if you’re working in a window and you drag the top of the window to the top of your screen, Windows will snap the bottom of the window to the bottom of the screen. This Event is triggered every time the player resizes or moves the game window.