Simon Donkers's Game Maker site siteSimon Donkers's Game Maker site
Version: GM 5+6 Read: 34077 Tutorial
Filesize: 6 kb Creative Commons License

Masks tutorial

1/52/53/54/55/5 (63 votes)

Note: this tutorial is made for GM5 and certain screenshots might have changed slighlty between versions

Have you ever wondered how to improve collision checking in your game, make sure your characters don’t get stuck anymore on the map, or how to make an isometric map. The answer is that you should use masks.

What are masks

A mask is a sprite that is used by Game Maker for collision checking instead of the original sprite. This is useful for instance if you have a sprite with a lot of tentacles. For instance take this space ship:
Space ship, copyright Simon Donkers

With collision checking the flag will be counted as a part of the ship. So shooting a missile at the flag will count as hitting the ship.

Space ship, copyright Simon Donkers

Even though the shot didn’t actually destroyed the ship. It only shot of the flag of the ship and then went past the ship. So with your game you don’t want that shooting at your flag counts as destroying the ship.

Space ship, copyright Simon Donkers

To do this you can use masks. You simply make a shape in the same size as the object you make the mask for. For instance:

Space ship, copyright Simon Donkers

Now the bullet would go past the ship. Only this doesn’t look very nice in your game. Now you could add this as an invisible object to the game and make it follow the ship and make all collision checking with this new object. Luckely Game Maker has a built in system for this. These are the masks. If you add both the first image to your game and the black image to your game and set them as mentioned below:

Game Maker object properties

You then will have excellent collision checking for your ship.

Animated sprites

Masks are also very useful when using animated sprites. Since the image changes every step the area the sprite takes in also changes every step. So it could be that during an animation in one frame you are walking past a wall while the next moment you are inside the wall. This makes that you suddenly stand still and are stuck in a wall. Luckily when using masks this will not happen since masks do not change for your object. It doesn’t matter which sub image is being displayed the mask always stays the same. So when using animated sprites together with complex collision checking it is always a good idée to have a mask.

Isometric maps
If you want to make an isometric game masks are also very important.

Monkey in isometric maze, copyright Simon Donkers, Image taken from Monkey Project

If you look at the example you see that the monkey is not capable of passing to the small parts between the walls. So the monkey can not walk around. Yet in your game you want to have that the unit can walk around through the map. Therefore we use a mask for the monkey. So we give the monkey a small mask about the size of his shadow and we also give all the walls a mask. This then will give:

 Monkey in isometric maze, copyright Simon Donkers, Image taken from Monkey Project

This maps looks a bit weird but if we remove all the images it will be like:

Monkey in isometric maze, copyright Simon Donkers, Image taken from Monkey Project

This is how the PC handles the game. It will simply use the black round image as main character and this will be used for collision checking. This while the user will only see a monkey in a maze and without seeing any of the black parts.

Final notes:

  • In this tutorial I used black as color for the masks. Please note that any color can be used for masks. Just make sure you only keep one color as background color
  • Within the game the masks will never be shown. When you assign a mask to an object you will at all time only see the image of the character.
  • If you do not want to use masks since they require that you add an extra image to the game for every sprite that needs collision checking you can also use the bounding box in the image properties. (Open the sprite in Game Maker. Set the bounding box to manual and give the left, right, top and down coordinates of the bounding box. The mask in that case is a rectangle with the given sizes)

This tutorial has been created by

Simon Donkers

User comments

 scorpius posted at 2005-05-28 19:12:20Quote
I use verry long game maker but thit i dindt know thx simon. I think i will not need it but it is good to know.
 timmeh posted at 2005-08-18 23:24:12Quote
Thanks! I read the manuel for this info and didn't quite get it... But now I understand perfectly!
 Amion posted at 2006-02-17 10:04:07Quote
Hi! I'm a newbie at GM, so I do not quite get it. I try to make an object that is at the exactly same level (depth) as the Hero-character, so that the hero won't need to walk around the object. I want him to walk right though, not over or under. I know it has something to do with variables, depth, -y and masks, but whatever I try nothing turns out as I want it to be. I would be glad if someone could help me. Thank you.
 Yushatak posted at 2006-03-01 23:56:13Quote
Hi Amion. What you're looking for is to check the "Solid" checkbox in your object that you want him to move through. The depth must also be a greater number than the character's, or else it will appear over him. You can do this in code with "solid=1", quite simple! gl.
 I love you posted at 2006-04-11 13:18:42Quote
I like it very usefull
 Mooshee posted at 2007-08-23 14:53:48Quote
Is there any way to have multiple masks on an object? I'm making a hunting game so i want headshots (lethal) and bodyshots (non-lethal). Is this possible in game maker???
 Tumie posted at 2007-10-07 13:39:39Quote
I look to the pictures and I understand it. Thanks! I can use this!
 old thing! posted at 2007-10-12 19:09:03Quote
Sorry but all will be now that at last.
Even they who's doesn't used it.
 eo rules posted at 2007-12-03 03:58:06Quote
wow, u just sold my biggest problem
 gmkid posted at 2008-03-05 08:22:37Quote
This was helpfull even thogh i have been doing gm for years i never thoght about lerning masks
 gamemakerdude posted at 2008-06-22 20:20:31Quote
Thanx Yushatak!!! Yes i know this isn't a reply to the masks tutorial, but you helped me with my BIGGEST, FATTEST, PROBLEM! I have been trying to make it so that in my driving game, when you run a person over, his corpse is covered by the car instead of covering the car, and now I have solved teh problem! Thanks again!
 Camala posted at 2008-07-08 22:05:04Quote
Thanks for uploading. I've been working on an isometric game, (called Blank--look for it sometime in the next couple years) for a bit, and I needed to learn masks.
 GmFreak posted at 2008-09-30 23:01:18Quote
Thanks, this helps a lot!!
 Bobnelly posted at 2008-10-14 22:48:54Quote
You guys are basic, masks are so easy. But Mooshee asked a good question about masks for headshots.
 KoneStudios posted at 2009-05-04 18:54:10Quote
Thank you for this awesome tutorial. It will help for my upcoming game Lift. Again. thanks.
 ?????? posted at 2009-09-26 01:22:09Quote
I need to now how to make isometric game please post a tutarial on that!
 Jamal posted at 2010-01-31 08:36:20Quote
Thank you very much Mr. Simon. I was baffled by masks before, and now I completely understand.
 ????? posted at 2010-05-06 16:56:15Quote
to many words could you make it easier im like 13 and im trying to my game in tech ed
 dijidog posted at 2010-06-08 06:52:46Quote
I will help you whoever posted last that is 13 years old. email me @

I am new to GM but I understand much of it.