Z
Ziliock
Guest
In game maker 8 it was simply with ATL but in Studio I can figure it out.
if(global.Paused == true){
for(var i = 0; i <= 11; i++){
if(alarm[i] > 0) alarm[i]++;
}
image_speed = 0;
return true;
} else {
image_speed = AnimationSpeed;
return false;
}
if(PauseCheck() == true) exit;
// Everything above here will be run no matter what.
if (global.pause > pause_layer) exit;
// Everything below here will not be run if paused.
/// HOLD a button to pause the game
var pause=false;
if (keyboard_check(vk_space)==true) // or the button you want
pause=true;
while(pause==true) // infinite loop
{
if (keyboard_check_direct(vk_space)==false)
pause=false;
}
Thanks you.Can you translate it to Drag'n Drop or very specific GML(Codes)?I usually do pretty much exactly what RangerX has suggested with a few minor differences.
1. I copy the application surface to "global.pauseSurface" so that I can deactivate application surface drawing. This helps me boost mobile game performance
2.Use the control object to deactivate everything and then create an instance of oPause.
3. use oPause to draw global.pauseSurface with a blur shader
oPause contains the pause menu. When you unpause the game,
the control object reactivates everything, including application surface drawing, destroys oPause, and frees the pause surface
Thanks you!How can I do that in Drag'n Drop? Or GML, but I'm terrible at GML(Codes) a very specific explanation would helpWhat I do is the following:
- Take a picture of the game to make a background with. (using "sprite_create_from_surface()")
- Deactivate everything except my Pause Menu object.
- Now you display the picture of the game as background, your menu on top.
- To unpause, I reactivate everything.
- Kill the menu and background.
// The game always draws to the "application_surface" (see docs for more info).
var width = surface_get_width(application_surface),
height = surface_get_height(application_surface);
// This will create a sprite from the application surface, which will be the screenshot of the game.
global.PauseScreenShot = sprite_create_from_surface(application_surface, 0, 0, width, height, false, false, 0, 0);
room_persistent = true;
global.RoomBeforePause = room;
room_goto(room_pause);
room_goto(global.RoomBeforePause);
// Only run the un-pause code if we actually un-paused.
if (global.RoomBeforePause != -1) {
global.RoomBeforePause = -1;
// Only do this if you--skipped step 1--created the pause screenshot of the game.
sprite_delete(global.PauseScreenShot);
}
I'm looking to use this method to pause my mobile game as I think it might be good for tutorials too. Thanks!I usually do pretty much exactly what RangerX has suggested with a few minor differences.
1. I copy the application surface to "global.pauseSurface" so that I can deactivate application surface drawing. This helps me boost mobile game performance
2.Use the control object to deactivate everything and then create an instance of oPause.
3. use oPause to draw global.pauseSurface with a blur shader
oPause contains the pause menu. When you unpause the game,
the control object reactivates everything, including application surface drawing, destroys oPause, and frees the pause surface
This looks like a cool solution. I have one question, didn't you forget to draw the global.PauseScreensShot in the Pause room?The easiest option is this...
It's super easy to create a pause menu if you use room persistence. The basic idea is that when you pause you set the current room to be persistent and then you change rooms to a "pause room," e.g. a room that acts as the pause menu. Then when you un-pause you change rooms to the room you where in before you paused and then you turn off room persistence.
Room persistence--if you don't already know--tells GameMaker to store everything that's happened in a room in memory so that when you leave the room and come back, the room is just the way you left it.
To do this you'll need 2 things:
- A global variable to store the current game room.
- A room that acts as the pause menu.
(Skip step 1 if you do NOT need a screenshot of your game to display behind the pause menu)...
When you un-pause do this...
- Create a screenshot of the game via the application surface.
Code:// The game always draws to the "application_surface" (see docs for more info). var width = surface_get_width(application_surface), height = surface_get_height(application_surface); // This will create a sprite from the application surface, which will be the screenshot of the game. global.PauseScreenShot = sprite_create_from_surface(application_surface, 0, 0, width, height, false, false, 0, 0);
- Set the current room persistence to TRUE.
Code:room_persistent = true;
- Change rooms to the pause room.
Code:global.RoomBeforePause = room; room_goto(room_pause);
- Changes rooms to the previous room we where in before we paused.
Code:room_goto(global.RoomBeforePause);
- When we've switched to the old room after un-pausing:
Code:// Only run the un-pause code if we actually un-paused. if (global.RoomBeforePause != -1) { global.RoomBeforePause = -1; // Only do this if you--skipped step 1--created the pause screenshot of the game. sprite_delete(global.PauseScreenShot); }
I would like to understand that, can you please explain it for a surfaces noob? Why do you deactivate application surface? How does it boost performance, I mean we are in pause mode just showing a screenshot, what performance do we boost here?1. I copy the application surface to "global.pauseSurface" so that I can deactivate application surface drawing. This helps me boost mobile game performance
If you're drawing the pause stuff to a new surface then deactivating the application surface won't affect the drawing of the pause stuff (application surface and a surface you create are two different 'screens' so to speak). As to the performance boost, the game will still be drawing application surface if you're simply drawing another surface over the top of it (i.e. the game is basically rendering two screens at once), so deactivating the application surface boosts performance as it removes the unnecessary drawing event. At least, that's what's happening to my limited surface knowledge.I would like to understand that, can you please explain it for a surfaces noob? Why do you deactivate application surface? How does it boost performance, I mean we are in pause mode just showing a screenshot, what performance do we boost here?
Where do you draw pause screen, after application surface is deactivated? Why bother?
thx
Ok, so I have used this method and it was so easy and fast, and it works perfectly (for now). I definitely recommend this method for a pause menu.The easiest option is this...
It's super easy to create a pause menu if you use room persistence. The basic idea is that when you pause you set the current room to be persistent and then you change rooms to a "pause room," e.g. a room that acts as the pause menu. Then when you un-pause you change rooms to the room you where in before you paused and then you turn off room persistence.
Room persistence--if you don't already know--tells GameMaker to store everything that's happened in a room in memory so that when you leave the room and come back, the room is just the way you left it.
To do this you'll need 2 things:
- A global variable to store the current game room.
- A room that acts as the pause menu.
(Skip step 1 if you do NOT need a screenshot of your game to display behind the pause menu)...
When you un-pause do this...
- Create a screenshot of the game via the application surface.
Code:// The game always draws to the "application_surface" (see docs for more info). var width = surface_get_width(application_surface), height = surface_get_height(application_surface); // This will create a sprite from the application surface, which will be the screenshot of the game. global.PauseScreenShot = sprite_create_from_surface(application_surface, 0, 0, width, height, false, false, 0, 0);
- Set the current room persistence to TRUE.
Code:room_persistent = true;
- Change rooms to the pause room.
Code:global.RoomBeforePause = room; room_goto(room_pause);
- Changes rooms to the previous room we where in before we paused.
Code:room_goto(global.RoomBeforePause);
- When we've switched to the old room after un-pausing:
Code:// Only run the un-pause code if we actually un-paused. if (global.RoomBeforePause != -1) { global.RoomBeforePause = -1; // Only do this if you--skipped step 1--created the pause screenshot of the game. sprite_delete(global.PauseScreenShot); }
Hello, sorry i necro this post but i was looking for a way of doing a pause menu and i liked this method, i only have one problem tho, how or where do i change the room's persistance back to false? I ask because in my pause menu i have a button that takes me back to the main menu and then, if i go back to that same room it is still persistent.The easiest option is this...
It's super easy to create a pause menu if you use room persistence. The basic idea is that when you pause you set the current room to be persistent and then you change rooms to a "pause room," e.g. a room that acts as the pause menu. Then when you un-pause you change rooms to the room you where in before you paused and then you turn off room persistence.
Room persistence--if you don't already know--tells GameMaker to store everything that's happened in a room in memory so that when you leave the room and come back, the room is just the way you left it.
To do this you'll need 2 things:
- A global variable to store the current game room.
- A room that acts as the pause menu.
(Skip step 1 if you do NOT need a screenshot of your game to display behind the pause menu)...
When you un-pause do this...
- Create a screenshot of the game via the application surface.
Code:// The game always draws to the "application_surface" (see docs for more info). var width = surface_get_width(application_surface), height = surface_get_height(application_surface); // This will create a sprite from the application surface, which will be the screenshot of the game. global.PauseScreenShot = sprite_create_from_surface(application_surface, 0, 0, width, height, false, false, 0, 0);
- Set the current room persistence to TRUE.
Code:room_persistent = true;
- Change rooms to the pause room.
Code:global.RoomBeforePause = room; room_goto(room_pause);
- Changes rooms to the previous room we where in before we paused.
Code:room_goto(global.RoomBeforePause);
- When we've switched to the old room after un-pausing:
Code:// Only run the un-pause code if we actually un-paused. if (global.RoomBeforePause != -1) { global.RoomBeforePause = -1; // Only do this if you--skipped step 1--created the pause screenshot of the game. sprite_delete(global.PauseScreenShot); }
Nah. Copy the "pause surface" to a buffer. If the surface is lost, you can regenerate it from the buffer. It's the same effect, but you don't need to worry about extra texture pages and extraneous sprite data floating around. Buffers are non-volatile, so you don't need to worry about them disappearing randomly. You just need to be sure you clean it up at the same time you clean up the pause surface.If you don't want to lose your "pause surface" that IS volatile, save your screen as a sprite like my method and not a surface.
Flush your sprite or surface based pause background as soon as the player unpauses.
if global.paused{
image_speed = 0;
speed = 0;
}
global.paused = false; //the game defaults to NOT PAUSED
if keyboard_check_pressed(vk_escape){ //or whatever key activates the pause screen
global.paused = true;
}
if global.paused{
instance_deactivate_all(true); //this deactivates all objects except the pause screen itself
}
if global.paused && keyboard_check_pressed(vk_escape){ //resume the game
global.paused = false;
instance_activate_all();
}
if global.paused{
draw your pause menu here.
}