© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2023
B. TyersGameMaker Fundamentalshttps://doi.org/10.1007/978-1-4842-8713-2_19

19. Effects

Ben Tyers1  
(1)
Worthing, West Sussex, UK
 
Graphical effects are important in most games. Whether it’s just a little sparkle effect or an explosion. Graphical effects can be done using sprites, built-in effects, or the Effects layers. The built-in effects allow for quick prototyping of a game, and can even be used in a finished project. Some examples would be
  • Visually showing the player that a button has been pressed.

  • Showing damage when hit by a bullet.

  • Explosion when an enemy dies.

Effects

A number of basic effects can be created with just one line of code, for example:
/// @description Simple effect
effect_create_above(ef_spark,mouse_x,mouse_y,2,c_white);

This would a create a spark effect at the mouse’s position.

Create an object obj_test and put this code in a Step Event, pop it into a room and test.

The general format used is:
effect_create_below(type,x,y,size,colour);
Note

Effect code does not need to be in a Draw Event, it can be in a Step Event, Key Press Event, etc. which can be very useful!

You’ll see that there are two options: effect_create_above() and effect_create_below(). The above option will draw above it’s default sprite or anything in its Draw Event, while below would draw beneath.

Another example would be that below, add this to your Step Event and test again:
if mouse_check_button_pressed(mb_left)
{
    effect_create_above(ef_explosion,mouse_x,mouse_y,2,c_red);
}

This creates an explosion effect each time the left mouse button is clicked.

There are several effects to choose from:
  • ef_cloud

  • ef_ellipse

  • ef_explosion

  • ef_firework

  • ef_flare

  • ef_rain

  • ef_ring

  • ef_smoke

  • ef_smokeup

  • ef_snow

  • ef_spark

  • ef_star

Try out some of these effects now, by editing the code in your Step Event.

Using randomness, you can create some cool effects. Try the following and see what it does:
if mouse_check_button_pressed(mb_left)
{
      effect_create_above(ef_flare,mouse_x,mouse_y,1,choose(c_blue,c_purple,c_green));
}

This will create a flare effect with a random color of blue, purple, or green, while the right button is being held down.

Now try this code:
if mouse_check_button_released(mb_left)
{
effect_create_above(choose(ef_spark,ef_smoke,
ef_explosion, ef_firework),mouse_x,
mouse_y,2,choose(c_white,c_grey));
}

which creates a random effect in white or grey.

Figure 19-1 shows these effects in action.

A Gamemaker Studio 2 screen of a random dot with trailing sparks.

Figure 19-1

Showing standard effect

Effect Layer

You can also create effects using the Effect Layer. A number of effects are available, with new ones added on a regular basis.

Start a new project, load in the ocean background and set it as a background for a room, as shown in Figure 19-2.

A screenshot of two panels. Rome editor has layer room 1 and selects the background. Room 1 panel has a view of the beach design in the grid.

Figure 19-2

Assigning a sprite as a background

Next, add an Effect Layer between the Instances and Background layers by clicking, as shown in Figure 19-3. The Effect Layer applies to layers below it, so in this case, the effects would be applied to Background and not Instances above it.

An illustration of the room editor screen has layers room1 and selects the effect 1 option. Highlights the create a new file option and the effect type as none.

Figure 19-3

Adding an effect layer

Now choose an effect, for example as shown in Figure 19-4.

An illustration of the room editor screen has layers room 1 and selects the effect 1 option. Effect 1 layer properties of room 1 highlight effect type as edge detect.

Figure 19-4

Choosing an effect

Have a play around choosing various settings for each effect, for example, as shown in Figure 19-5.

An illustration of the room editor screen has layers room 1 and selects the effect 1 option. Effect 1 layer properties of room 1 highlight effect type as underwater.

Figure 19-5

Trying out various effects and settings

Basic Projects

  1. A)

    Set key S & R to change the weather between snow and rain.

     
  2. B)

    Create fireworks in random size and color.

     

Advance Projects

  1. C)

    Use the effects layer to create an underwater scene with wave effects.

     
  2. D)

    Make a system that shakes the room when space is help down.

     

Useful Functions

Pre-rendered sprite animations can also be used to create some awesome effects, for example, a sprite sheet with explosions, as shown in Figure 19-6.

A series of illustrations in 8 columns and 7 rows. It exhibits the stage of a fire blast.

Figure 19-6

Showing a sprite explosion sheet

GameMaker also allows use of a particle system; if you’re feeling adventurous, then look into this.

fx_* functions allow controlling the effects layer whilst your game is running.

Summary

You can now perform basic effects, both in code and using effects layers.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.160.43