• 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!

Is it possible to display object's sprite when the game is paused?

T

tommyleug1991

Guest
Hello everyone, I would like to create the game with pause the game function
My code in step tag:

GML:
key_P = keyboard_check_pressed(ord("P"));
if(key_P){
  paused = !paused;
}

if(paused){
    instance_deactivate_all(true); // 1
}else{
    instance_activate_all();
}

but I find when I pause the game, the sprite is disappeared
Is it possible to show object's sprite when the game is paused?
 

FoxyOfJungle

Kazan Games
You must save the screen before pausing the game like this:

GML:
var _screenshot = sprite_create_from_surface(application_surface,0,0,surface_get_width(application_surface),surface_get_height(application_surface),0,0,0,0);

Then just draw the sprite:
GML:
draw_sprite(0,0,_screenshot);
You must do this on the object that has not been disabled, usually the object on which you have disabled all instances. (Remember to prevent the current object from being disabled in the instance_deactivate_all() function itself).

When you unpause, you must delete the _screenshot sprite to not cause memory leaks.
 

Evanski

Raccoon Lord
Forum Staff
Moderator
Where ever you call your pause event
Code:
 ids_list = ds_list_create();
 var list = ids_list;
 with (all)
 {
     ds_list_add(list, id);
 }
In the draw event of your pause object
GML:
script_execute(scr_pauseDraw);
in scr_pausedraw
GML:
function scr_pauseDraw() {

    var size = ds_list_size(ids_list);
        for (var i = 0; i < size; ++i)
        {
            var inst = ids_list[| i];
            if !(inst.sprite_index = -1)&& (inst.sprite_index != spr_collisonbox)
            {
                draw_sprite_ext(inst.sprite_index, inst.image_index, inst.x, inst.y, inst.image_xscale, inst.image_yscale, inst.image_angle, c_white, inst.image_alpha);
        
            }
        }
}
 
Last edited:
Top