GMS 2 [Help] Pause screen

S

SaloXtreme

Guest
Hello. I'm completely new to GM and programming, so I mostly don't know what I am doing.
I want to make a pause screen that stops all the sprites and adds a dark overlay.

So far I am using instance_deactivate_all(). I tried to implement something with surfaces but it didnt work. I dont know how to code it.
 

samspade

Member
Hello. I'm completely new to GM and programming, so I mostly don't know what I am doing.
I want to make a pause screen that stops all the sprites and adds a dark overlay.

So far I am using instance_deactivate_all(). I tried to implement something with surfaces but it didnt work. I dont know how to code it.
There are lots of way to do pause screens depending upon what you want. But without more specifics it's hard to give a specific suggestion. There are a number of tutorials and free market place apps for it as well.
 
S

SaloXtreme

Guest
What Im trying to do is to make it looks like the game freezes when I pause. Because I use instance_deactivate all sprites dissapear. I have seen many tutorials on how to do this, but I cant get it to work. Also, a have a GUI on the upper left corner of my screen. When I unpause, the GUI moves further left and almost out of vision.

This is the code I am using for pausing. Its an object:

if not pause_ {
pause_ =true;
instance_deactivate_all(true);
} else {
pause_=false;
instance_activate_all()
}

And this is the GUI I mentioned:

draw_set_font(font1);
draw_set_colour($FF2957E2 & $ffffff);
draw_set_alpha(($FF2957E2 >> 24) / $ff);
draw_text(x + 0, y + -250, string("Time: ") + string(myTime));
 

DT Mark

Member
In order to make it look like it's frozen, you should:
- capture an image of the game right before pausing
- deactivate the objects
- display the captured image with an overlay

In order to "capture an image", you'd have to copy the application surface to a temporary surface, then turn that surface into a background (or a sprite in GMS2, I think)
In order to "display the image", you'd just need to draw that background/sprite

Now if you can't manage to get it working because you're not at ease with surfaces, here's the script I use to capture the screen and store it into a background:
Code:
/* SCRIPT */
//scr_screen_capture();

//variables
var ret = -1;
var sfc_width = surface_get_width(application_surface);
var sfc_height = surface_get_height(application_surface);

//create a drawing surface
var sfc = surface_create(sfc_width,sfc_height);
surface_set_target(sfc);

//clear the surface you created just in case
draw_set_colour_write_enable(0, 0, 0, 1);
draw_clear(c_black);
draw_rectangle_colour(0, 0, sfc_width, sfc_height, c_black, c_black, c_black, c_black, 0);
draw_set_colour_write_enable(1, 1, 1, 0);

//capture screen on the surface
draw_surface(application_surface, 0, 0);
ret = background_create_from_surface(sfc,0,0,sfc_width,sfc_height,false,false); 
//if it doesn't work with backgrounds, try creating a sprite from the surface?
//this might be very heavy though

//finalise and clear surface from memory
surface_reset_target();
draw_set_colour_write_enable(1, 1, 1, 1);
surface_free(sfc);
return ret;

/*
This script will return the background itself.

Now when you pause the game, you'd just need to create a variable that holds the background:
pause_bg = scr_screen_capture();

Then draw it when your pause_ variable is true:
if background_exists(pause_bg) draw_background_ext(pause_bg, 0, 0, 1, 1, 0, -1, 1);
(Eventually you can draw a transparent black rectangle over it)

When your pause_ variable is false, don't forget to destroy the background:
if background_exists(pause_bg) background_delete(pause_bg);
*/

Hope this helps!
 
Last edited:
Top