Search The Glog

Tuesday, July 16, 2013

Simple pause tutorial in gamemaker

Here is a simple, yet very effective pause tutorial for your gamemaker games. I also used it in most of my games, for pausing the game, displaying achievements list and tutorials. It can be used for other game stopping stuff, like displaying a pop-up, the highscores list, etc.

UPDATED TO GAMEMAKER STUDIO 1.3.

Here it goes !
First you will need to create an object : ob_pause. Don't attach any sprite to it. Next create a background back_pause and put any image you want to be shown behind the pausing event.

Then, in the Create event put the following code:
keyboard_clear(vk_space); //clears the pause key
instance_deactivate_all(1); //deactivates the game objects but not the pause object
x=room_width/2;
y=room_height/2;
In the Draw event use the code:
draw_background_stretched(back_pause,0,0,room_width,room_height); //draws the background of your choice
draw_set_color(c_black);
draw_set_alpha(0.7);
draw_roundrect(x-100,y,x+100,y+80,0);
draw_set_alpha(1);
draw_set_font(font_game);
draw_set_color(c_yellow);
draw_set_halign(fa_center);
draw_text(x,y+10,'Game paused !');
draw_text(x,y+40,'Press Space to continue !');
And in the Release Space key:
instance_activate_all();
instance_destroy(); //activates the game object and destroys the pause object
Lastly, when you need to pause the game, just create ob_pause at coordinates (0,0) at keyboard Space event.

Here you can download a simple demo, with more comments to the code ! Note that I replaced the config folder because of the size of it (4Mb) !!