#pause screen help
5 messages · Page 1 of 1 (latest)
For me, I had to make an object titled Opause with no sprite, and you would have to place it in every room you would like your player be able to pause. Here are the different events.
Create:
pause=false;
pauseSurf=-1;
pauseSurfBuffer=-1;
resW=1920;
resH=1080;
Clean Up:
if(surface_exists(pauseSurf))surface_free(pauseSurf);
if(buffer_exists(pauseSurfBuffer))buffer_delete(pauseSurfBuffer);
Draw gui:
if (pause)
{
draw_set_color(c_black);
draw_set_alpha(.5);
draw_rectangle(0, 0, room_width, room_height, false);
draw_set_alpha(1);
draw_set_color(c_white);
draw_set_font(Fpixel);
draw_text(288, 511, "Game is Paused. Press P to resume\n \nPress Backspace to quit game");
}
And then theres Post Draw:
gpu_set_blendenable(false);
if(pause)
{
surface_set_target(application_surface);
if(surface_exists(pauseSurf)) draw_surface(pauseSurf,0,0);
else // restore from buffer if we lost the surface
{
pauseSurf = surface_create(resW,resH);
buffer_set_surface(pauseSurfBuffer,pauseSurf,0);
}
surface_reset_target();
}
if(keyboard_check_pressed(ord("P")))// Toggle pause(Whatever condition/trigger you like)
{
if(!pause)// pause now
{
pause=true;
// deactivate everything other than this instance
instance_deactivate_all(true);
// NOTE:
// If you need to pause anything like animating sprites,tiles,room backgrounds
// you need to do that separately,unfortunately!
// capture this game moment(won't capture draw gui contents though)
pauseSurf=surface_create(resW,resH);
surface_set_target(pauseSurf);
draw_surface(application_surface,0,0);
surface_reset_target();
// Back up this surface toabuffer in case we lose it(screen focus,etc)
if(buffer_exists(pauseSurfBuffer)) buffer_delete(pauseSurfBuffer);
pauseSurfBuffer=buffer_create(resWresH4,buffer_fixed,1);
buffer_get_surface(pauseSurfBuffer,pauseSurf,0);
}
else // unpause now
{
pause=false;
instance_activate_all();
if(surface_exists(pauseSurf))surface_free(pauseSurf);
if(buffer_exists(pauseSurfBuffer))buffer_delete(pauseSurfBuffer);
}
}
if (pause)
{
if keyboard_check(vk_backspace)
{
game_end()
}
}
gpu_set_blendenable(true);