How to Use Decals with Surfaces in GameMaker: Studio - dummies

How to Use Decals with Surfaces in GameMaker: Studio

By Michael Rohde

In the Surfaces tutorial game of GameMaker: Studio, there are Instances called decals. Decals can provide graphical effects but don’t interfere with the gameplay. Just as with Objects and Instances, you want to keep the number of decals that appear in the game to a minimum; otherwise, your game may run very slowly and will eventually crash.

You can draw decals on the Surface to help stop your game from slowing down or having issues.

The following procedure picks up from the in-software Surfaces tutorial. To start, you create an Object that draws the Sprites for the decals that will last a very short amount of time, before being destroyed. This will allow the game to appear to have a million Instances, but it will really have very few.

To draw decals on the Surface, follow these steps:

  1. With the Surfaces tutorial open, from the Resource tree, right-click Objects and select Create Object.

    The Object Properties appear.

  2. In the Name field, type obj_Decal_Surface.

  3. Choose Add Event→Create.

    The Create Event appears in the Events section.

  4. Drag and drop an Execute Code Action from the Control tab to the Actions section.

    A code window appears.

  5. In the code window, type the following:

    surf = -1;

    This code creates a variable for the Surface.

  6. Click the green check mark.

    The code window is saved and closed.

To free up the memory for when you no longer want the decal effect, follow these steps:

  1. From the obj_Decal_Surface Object Properties, choose Add Event→Other→Room End.

    The Room End Event appears in the Events section.

  2. Drag and drop an Execute Code Action from the Control tab to the Actions section.

    A code window appears.

  3. In the code window, type the following:

    if surface_exists(surf)
    {
    surface_free(surf);
    }
  4. Click the green check mark.

    The code window is saved and closed.