• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Pause Game

Zaksley

Member
Hi guys,
I would like be able to pause my game for differents features (Pause for the player, pause to craft things, ..).
Let's focus on a basic pause for now.

I saw 2 possibilities :
1) Deactivate ennemis and draw their sprites
2) Using surface stuff from Game Maker and deactivate ennemies

I still think the second option might be very good for my project and I found this tutoriel from Game Maker : https://www.yoyogames.com/blog/551/coffee-break-tutorials-pausing-your-game-gml

So, I tried it and I have some issues :
When I pause the game, the sprites are shifted (enemies disappear so, it's ok but the backgrounds, it's not at the right position).

I'm sharing 2 pictures, the one without the pause and the one with the pause.
I put my code below but it's the same than the tutorial.

Step code for the object pause
Code:
if room == room_game
{
    if keyboard_check_pressed(ord("P"))
    {
        paused = !paused;
        if paused == false
        {
            instance_activate_all();
            surface_free(paused_surf);
            paused_surf = -1;
        }
    }
    
    if paused == true
    {
         //nothing
    }
}
Draw event in the pause object
Code:
if paused == true
{
    if !surface_exists(paused_surf)
    {
        if paused_surf == -1
        {
            instance_deactivate_all(true);
            
        }
        
        paused_surf = surface_create(room_width, room_height);
        surface_set_target(paused_surf);
        draw_surface(application_surface, 0, 0);
        surface_reset_target();
        
    }
    else
    {
        
        draw_surface(paused_surf, 0, 0);
    }
}
 
Top