1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice
  2. NOTICE: We will be applying a Xenforo update on Tuesday 25th of February. This means that from approximately 10:00 to 14:00 BST the forums will be offline (or possibly longer). Sorry for the inconvenience! Official Announcement here.

GMS 2 [Help] Pause screen

Discussion in 'Programming' started by SaloXtreme, Oct 22, 2017.

  1. SaloXtreme

    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.
     
  2. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    2,234
    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.
     
  3. SaloXtreme

    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));
     
  4. DT Mark

    DT Mark Member

    Joined:
    Jun 24, 2017
    Posts:
    19
    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: Oct 23, 2017
  5. Noba

    Noba Member

    Joined:
    May 6, 2017
    Posts:
    367

Share This Page