How to Create Shadows in GameMaker: Studio - dummies

How to Create Shadows in GameMaker: Studio

By Michael Rohde

GameMaker: Studio allows you to add shadows to Instances and Surfaces. The following procedure does not use Surfaces, but it does provide an example of how to add a shadow effect to Instances.

This procedure uses examples from the in-software tutorial, Surfaces_Part 1. Before you start working on creating a Surface, take a moment to become familiar with the tutorial and how it works. In the game, you can use the arrow keys to move and the mouse to aim and shoot. The right mouse button throws a grenade.

To open the tutorial, from the New Project window, click the Tutorials tab. An expandable list of tutorials appears on the left. Click to open a list of Intermediate tutorials and then choose Surfaces_Part 1.

While playing the game, you may have noticed that the player and the enemies have subtle shadows. The following procedures show you how to add shadows to the walls to create a more 3D effect. To add shadows to the walls, follow these steps:

  1. With the Surfaces tutorial open, from the Resource tree, in the Objects folder, double click obj_Wall.

    The Object Properties appear.

  2. Choose Add Event→Draw→Draw.

    The Draw Event appears in the Events section.

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

    A code window appears.

  4. In the code window, type the following:

    draw_sprite_ext(sprite_index, 0, x - 16, y + 16, 1, 1, 0, c_black, 0.5);
  5. Click the green check mark.

    The code window is saved and closed.

If you run the game now, you should see a very basic shadow effect on the walls, as shown in the figure. To run the game, from the main menu, choose Run→Run Normally.

A basic shadow effect.
A basic shadow effect.