Lives to your Game
When using something
like lives in a game, you have to track it using variables.
There are several built in variables in GameMaker
including score, lives and health.
Create a new object
and call it, obj_setvariables
This object will
set how many lives you start with, the same object can be
used to set other variables such as score, coins etc.
In GameMaker, there are actions to set, check and draw the
lives, health and score variables. These variables are global
variables (valid in any room) , it's up to you to set and
Here are the actions
used to set, check and draw the lives on the screen.
the Lives at the Start of the Game
a Create event to the obj_setvariablse object, on this event,
you will set your lives and health etc.
From the Score
tab, drag in the Set Lives Action
Set the New Lives
You MUST put this
obj_setvariables object in your first room, if you don't,
the lives won't be set when the game starts. You can also
put this object in your game over screen to reset the lives
and score for when the player continues the game. Every time
you go to a room with this object in, it will reset the lives
and anything else you set on it so be careful where you use
Doing this will
set the Lives as 3 when the game is started.
a Life when you Click a Bomb
Now we want to
change the game up so when you click a bomb, you lose a life.
(instead of dying right away)
Add the Set Lives
Set the New Lives as, -1 and tick relative, this will take
away one life from your total.
Add the No More
Lives Event from the Other Events Group
In this event,
put what actions you want to happen when the character runs
out of lives.
Add the object
to your Level 1
the Lives on the Screen
Now the game has
lives, the next thing we need to do is show the user how many
they have left. Drawing onto the screen is all done with an
Create a new object
and call it, obj_displaylives, don't give it a sprite.
Add the Draw Event.
This is event is used to draw onto the screen.
Draw Lives as
This draws the
number of lives using sprites
On the settings
menu, put in what position you want to draw the lives at on
In this example
I have put 10x and 10y, this will draw it at the top left
of the level. Select what sprite to use to represent one life.
Now change when
the game ends (i.e. When you are out of lives)