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

Coding problem (pause menu)

P

Pudding

Guest
so ive been trying to get a working pause menu up and running that captures the view thats currently on the screen and displays it as a surface when the game pauses (when paused the screen is supposed to look like it Everything has frozen in place)

this is my current code (Event: presskey_escape Action: code)

pause = pause + 1

if pause == 1
{
surf = surface_create(room_width, room_height);
surface_set_target(surf);
surface_reset_target();
draw_surface(surf, room_width - view_xview[0], room_height - view_yview[0]);
}
pause = 2

if pause == 2
instance_deactivate_all(true)

if pause == 3
{
surface_free(surf);
instance_activate_all()
pause = 0
}

*note that "pause = 0" from the start and "surf = noone" in a create event.

im sorry if im not using terms commonly practiced on this site but im kinda new to this as a a whole now go and solve the problem for me thank you!
 

Xer0botXer0

Senpai
You haven't actually drawn anything onto the surface.

You created the surface, set its dimensions, set target surface from I think it's called application surface or such to your declared surface, then you reset the surface which would clear anything on it I believe, then you draw the surface within the confines of view[0].

From what I understand all of that seems right, the problem is that you haven't drawn the room onto the surface, the room is currently drawn onto the application surface.

surface_copy(surf, 0, 0, application_surface);
https://docs.yoyogames.com/source/dadiospice/002_reference/surfaces/surface_copy.html

But I dont think you actually need to go through the trouble of using surfaces for this.

https://docs.yoyogames.com/source/d...ssets/sprites/sprite_create_from_surface.html
sprite_create_from_surface

This allows you to simply create a sprite from the surface then draw it in the draw event and use a boolean to toggle it on or off, on when the menu is open and off when you're back in game.
 
P

Pudding

Guest
You haven't actually drawn anything onto the surface.

You created the surface, set its dimensions, set target surface from I think it's called application surface or such to your declared surface, then you reset the surface which would clear anything on it I believe, then you draw the surface within the confines of view[0].

From what I understand all of that seems right, the problem is that you haven't drawn the room onto the surface, the room is currently drawn onto the application surface.

surface_copy(surf, 0, 0, application_surface);
https://docs.yoyogames.com/source/dadiospice/002_reference/surfaces/surface_copy.html

But I dont think you actually need to go through the trouble of using surfaces for this.

https://docs.yoyogames.com/source/dadiospice/002_reference/game assets/sprites/sprite_create_from_surface.html
sprite_create_from_surface

This allows you to simply create a sprite from the surface then draw it in the draw event and use a boolean to toggle it on or off, on when the menu is open and off when you're back in game.
thanks for the reply i appreciate it
but i am a bit confused where to place everything in the code if i still want to use surfaces and get the same effect.
 

Xer0botXer0

Senpai
Code:
pause = pause + 1

if pause == 1
{
surf = surface_create(room_width, room_height);
surface_set_target(surf);
surface_copy(surf, 0, 0, application_surface);
draw_surface(surf, room_width - view_xview[0], room_height - view_yview[0]);
surface_reset_target();
}
pause = 2

if pause == 2
instance_deactivate_all(true)

if pause == 3
{
surface_free(surf);
instance_activate_all()
pause = 0
}
surface_copy and draw_surface, im not sure which order.

You need to have any drawing of surfaces in the draw event.
so
"draw_surface(surf, room_width - view_xview[0], room_height - view_yview[0]);"
would have to be in a draw event... which means that you can use something like a boolean to enable that line of code to run once the game reaches "surface_set_target.


surface_reset_targets sets the target surface to the application surface, so when ever you draw something onto a surface you use surface_set_target, then draw then surface_reset_target once you're done.
 

Xer0botXer0

Senpai
There's pretty much an order in which to work with surfaces.

Declare surface
set surface target
draw onto surface
draw the surface
reset surface target..

There's also clearing the surface. but for still images that's not necessary. I think surface_free does that too, im not sure.
 
Top