Gw Temp


Tutorial - 'Special Effects in Game Maker' by Kuro

An item about Gamemaker posted on


A well written tutorial on making special effects in Gamemaker!!


Quicktorial #1: Special Effects in Game Maker

I was bored tonight and I decided to type up another tutorial, but I decided it should be something quick and fun. So I present to you, the first Quicktorial! Check it.

In Rm2k, special effects like battle animations were simple to do since the engine was already there, but in Game Maker, its a whole new process when implementing special effects into your game. So here's my method on how to create simple one-shot (or multi-shot) effects in Game Maker using sprites, one object, and two scripts. (along with some constants to simplify things)

First off, you're going to want to make your sprites. If you want to import a Rm2k battle animation, use the 'Create from Strip' option under the sprite editor menu bar. A Rm2k battle animation has each cell separated into 80x80 squares in case you didn't know.

Nextly.... Create a new object and call it 'fx' or whatever you want. In fx, Add a Create, Step, and Draw event. In the Create event, add a new code snippet and type/copy this:

// m_fxClassType controls the type of animation class we want (example: m_fxClassType could be a constant value aptly named Explosion).
m_fxClassType = noFX;

// m_fxSubType is the sub number of the current animation class defined by m_fxClassType
m_fxSubType = noFX;

// m_repeat controls how many times we show this fx
m_repeat = 0;

// m_count controls how many times we've shown this fx
m_count = 0;

// bEnabled checks to see if the fx should run
m_bEnabled = false;

Okay, now in the Draw Event, add this:

// Check to see if fx is enabled
if(m_bEnabled && global.fxON){
if(self.sprite_index != -1){

Good, now in the Step event, add this:

if(m_bEnabled && (m_fxClassType != noFX && m_fxSubType != noFX){
self.sprite_index = global.fx_list[m_fxClassType,m_fxSubType];
if(self.image_index == self.image_number - 1){
m_count += 1;
if(self.m_count >= self.m_repeat + 1){

That's it for the object! Now create a new script called InitializeFX (or whatever...) and add this code to it:

// Script: InitializeFX()
global.fx_list[i,j] = noFX;
global.fxON = true;
global.maxFX = 10;

// TODO: Set global.fx_list[x,y] values below

You'll come back to the TODO comment later. Create another script called CreateFX (... whatever) and add this:

// Script: CreateFX(argument0 = default_on, argument1 = fxClass, argument2 = fxSub, argument3 = fxReps, argument4 = x, argument5 = y)
if(instance_number(fx) < global.maxFX){
iid = instance_create(x,y,fx);

iid.m_fxClassType = argument1;
iid.m_fxSubType = argument2;
iid.m_repeat = argument3;

iid.m_bEnabled = argument0;

Booyah. Now save your game if you haven't already. Now there's only two things left to do. One is to add some much-needed constant values like noFX (which I usually leave at zero) and Two is to go back and fill out the TODO section in InitializeFX. Here's how you should go about doing that:

Each 'Class Type' in the global.fx_list should relate to a type of basic animation such as an explosion or an emote. The 'Sub Type' can be an assortment of your sprites that can be classified under the 'Class Type.' Still confused? Here's an example:

Let's say we have three base types of animations in our game: Explosions, Emotes, and Auras. Under Explosions, we have two types of explosion animations, a fireball explosion and a nuclear mushroom cloud explosion. Under Emotes, we have the basic sweat drop and angry emote animations. And under Auras we just need one, a DBZ-ish type of power up flame. By using the above system, we can easily define our sprites early on during InitializeFX and whenever we need to show an effect, we just call CreateFX with the specified parameters! For instance:

// Defined as a constants in Game Options
// fx_class_explosion = 0, fx_class_emotes = 1, fx_class_auras = 2
// fx_sub_n = n (think algebra people)
// sprite_fx_whatever = a sprite you create

global.fx_list[fx_class_explosion,fx_sub_00] = sprite_fx_fireball;
global.fx_list[fx_class_explosion,fx_sub_01] = sprite_fx_nuclear;
global.fx_list[fx_class_emotes,fx_sub_00] = sprite_fx_sweatdrop;
global.fx_list[fx_class_emotes,fx_sub_01] = sprite_fx_angry;
global.fx_list[fx_class_auras,fx_sub_00] = sprite_fx_dbzFlare;


// Using CreateFX on a DBZ warrior. He's angry and charges his Aura. GOODNESS!

Simple, right?

Now this tutorial leaves a lot to be desired. Real-time transparency, scaling, and 2D depth ordering are a few off the top of my head. But the framework is here, so all that's really left is for you to find some way to use it. That's one down, two to go.

Next Time, Quicktorial #2: CMSs in Game Maker. See ya then.