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

SOLVED Pause menu Surface_draw

S

Stratos.la

Guest
i have a pause button that brings up a menu with options. i managed to make it take a screenshot and show it but it doesn't work as it should! when i first press the button it just shows a black overlay and nothing else. on second press (pause on, pause off, pause on again ) it does show the screenshot and the pause menu but then the menu doesn't go away!

pause button create
GML:
globalvar PAUSED;
PAUSED = false;
pausesrf = surface_create(1920,1080)
pause button left pressed
GML:
/// @description Open Options
PAUSED = !PAUSED
if (PAUSED)
{ 
    if !surface_exists(pausesrf)
        {
            pausesrf = surface_create(1920,1080);
            surface_copy(pausesrf,0,0,application_surface)
        }
    instance_create_layer(room_width/2,room_height/2,"Instances_2",obj_paused_menu)
    instance_deactivate_all(true)
}
else if (!PAUSED)
{
    if surface_exists(pausesrf) surface_free(pausesrf)
    instance_destroy(obj_paused_menu);
    instance_activate_all();
}
and the draw event

GML:
if PAUSED
{
    if surface_exists(pausesrf)
    {
        draw_surface(pausesrf,0,0)
    }
    //////////
    draw_set_color(c_black)
    draw_set_alpha(0.5)
    draw_rectangle(0,0,room_width,room_height,0)
    draw_set_alpha(1)

    if global.survival == 1
    {
    draw_sprite(sMapReturnSurvival,0,x,y+156)
    }

}
The obj_pausemenu created has a sprite and some virtual buttons in it nothing else
 
Last edited by a moderator:
S

Stratos.la

Guest
i did change the code a bit based on the manual and declared the surface in the draw event but then it doesnt draw the game screenshot and for some reason the pause menu doesnt get destroyed and since it has virtual buttons in it i can press them even though its not visible!
 
C

cidyuki

Guest
I try to make a pause menu too
Did you solve your issue ?
Do the if statement work well on draw event ?
 
C

cidyuki

Guest
GML:
    instance_create_layer(room_width/2,room_height/2,"Instances_2",obj_paused_menu)
    instance_deactivate_all(true)
Maybe because the instance "obj_paused_menu" is deactivate.
I think that instance_deactivate_all(true) only not desactivate the current object.
 
S

Stratos.la

Guest
ok so yea i managed although i dont know if its the proper way but it works.
create event
GML:
globalvar PAUSED;
PAUSED = false;
pausesrf = -1;
draw event
GML:
draw_self();
if PAUSED
{
    
    if surface_exists(pausesrf)
    {
        draw_surface(pausesrf,0,0)
    }
    //////////
    draw_set_color(c_black)
    draw_set_alpha(0.5)
    draw_rectangle(0,0,room_width,room_height,0)
    draw_set_alpha(1)
}
else if !PAUSED
{
    if surface_exists(pausesrf)
    {surface_free(pausesrf)}
}
left pressed event
GML:
PAUSED = !PAUSED
if (PAUSED)
{   
    if !surface_exists(pausesrf)
        {
            pausesrf = surface_create(room_width,room_height);
            surface_copy(pausesrf,0,0,application_surface)
        }
    instance_deactivate_all(true)
    instance_create_depth(room_width/2,room_height/2,-100,obj_paused_menu)
}
else if (!PAUSED)
{
    instance_activate_all();
    if surface_exists(pausesrf)
    {surface_free(pausesrf)}
    instance_destroy(obj_paused_menu);
    instance_destroy(oSettingsButton);
    instance_destroy(oQuitButton);
    instance_destroy(oMapButton);
    instance_destroy(oResumeButton);
    
}
the obj paused menu has different buttons spawned in its create event. initially i tried to make them dissapear together with the obj_paused menu but couldnt so i delete them one by one if paused is false. im sure there is a way to actually delete everything together but for now this works for me!
 
C

cidyuki

Guest
In my case I use this tutorial :

You can maybe use an array and for statement to delete all the buttons.
 
Top