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

Creating new objects on the surface

G

GhostGK

Guest
Hello, all...
I have a pause system that deactivates all objects, and uses surface functions to draw the app surface (game screen) + transparent square on top of that, giving it a transparent pause effect..
Here's how i do it in code..

In create event of pause obj...
Code:
global.pause = true; //variable to know when the pause is active
surf_pause = surface_create(view_wview[0], view_hview[0]);//Create surface
gui_width = view_wport[0];
gui_height = view_hport[0];

surface_set_target(surf_pause);
draw_clear_alpha(c_black,0); // Clears surface.
draw_enable_alphablend(false);
draw_surface(application_surface,0,0);
draw_enable_alphablend(true);
surface_reset_target();

instance_deactivate_all(true); //deactivate all other instances
audio_pause_all(); //pause all sounds
In draw event...
Code:
///Draw the surface

if(surface_exists(surf_pause))
    {
    draw_enable_alphablend(false);
    draw_surface(surf_pause, view_xview[0], view_yview[0]);
    draw_enable_alphablend(true);
    }
else
    {
    surf_pause = surface_create(view_wview[0], view_hview[0]);
    }
In GUI Draw event...
Code:
///Draw background

var c_last = draw_get_color();;
//Draw semitransparent square
draw_set_color(c_black);
draw_set_alpha(0.5);
draw_rectangle(0,0, gui_width, gui_height,0);
draw_set_alpha(1);
draw_set_color(c_last);
Now that problem is that my menu system works with objects..
So, to make a pause menu, i have to create the menu objects, after all those stuff up there, i.e. over all those surfaces & things..
Problem is they don't show up..

I created the pause menu object that will create other objects (buttons), 1 step after the Create Event with a timer..
But, they don't show up.. Their functions don't work either (actions, menu sounds, etc..)

Any idea what I am overlooking?
 

jo-thijs

Member
Code:
surface_set_target(surf_pause);
draw_clear_alpha(c_black,0); // Clears surface.
draw_enable_alphablend(false);
draw_surface(application_surface,0,0);
draw_enable_alphablend(true);
surface_reset_target();
Couldn't this part just be done by surface_copy?

I would also recommend you take a look at buffer_get_surface and buffer_set_surface,
in order to save the screenshot even if the player minimizes the game or something linke that.

As for why the other menu objects are not working,
maybe they are deactivated by the instance_deactivate_all(true) in the code you gave.
Perhaps they are working, but are not visible, because they are drawn behind the screenshot.

Could you provide more information as to when exactly every object is created?
Maybe you should place some show_message(...) in create events to make sure everything happens in the order you expect them to happen.
 
G

GhostGK

Guest
Code:
surface_set_target(surf_pause);
draw_clear_alpha(c_black,0); // Clears surface.
draw_enable_alphablend(false);
draw_surface(application_surface,0,0);
draw_enable_alphablend(true);
surface_reset_target();
Couldn't this part just be done by surface_copy?

I would also recommend you take a look at buffer_get_surface and buffer_set_surface,
in order to save the screenshot even if the player minimizes the game or something linke that.
Thanks for your tips, jo-thijs..
I'll look into them.. :D

As for why the other menu objects are not working,
maybe they are deactivated by the instance_deactivate_all(true) in the code you gave.
Perhaps they are working, but are not visible, because they are drawn behind the screenshot.

Could you provide more information as to when exactly every object is created?
Maybe you should place some show_message(...) in create events to make sure everything happens in the order you expect them to happen.
The main object that will create the pause menu "obj_pause_menu" is created after 1 step (via alarm function) of pause/instance_deactivate_all..
So, it should not be affected by instance_deactivate_all, rt?
After being created, that object will create other objects for buttons and input methods, in its create event..

I just tried the show_message to quickly see it they are all being created properly..
Turns out only the Main "obj_pause_menu" is being created, and its create event isn't even running!

Did "obj_pause_menu" got affected by instance_deactivate_all?
I tried insyance_activate_object(obj_pause_menu) in the alarm event that created it.. no luck.. Any idea?
 

jo-thijs

Member
I need more information to be sure on what's going on.
Could you give the object information of every relevant object?
 
G

GhostGK

Guest
The object that will perform the pause and create the effect...
Information about object: obj_pause
Sprite:
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

///Initialize Variables

global.pause = true; //variable to know when the pause is active
surf_pause = surface_create(view_wview[0], view_hview[0]);//Create surface
gui_width = view_wport[0];
gui_height = view_hport[0];

surface_set_target(surf_pause);
draw_clear_alpha(c_black,0); // Clears surface.
draw_enable_alphablend(false);
draw_surface(application_surface,0,0);
draw_enable_alphablend(true);
surface_reset_target();

instance_deactivate_all(true); //deactivate all other instances
audio_pause_all(); //pause all sounds

//to make sure controls are working
scr_define_controls();

///Timer for menu creation
alarm[1] = 1;

Destroy Event:
execute code:

///Destroy surface

surface_free(surf_pause);

Alarm Event for alarm 1:
execute code:

///ini obj for menu
pause_menu = instance_create(obj_pause_menu, x, y);

Step Event:
execute code:

///Controls reading

scr_read_controls();

End Step Event:
execute code:

///Resuking with esc key

if global.pause = true
{
if global.k_esc
{
surface_free(surf_pause); //Clear surface
draw_enable_alphablend(true);
global.pause = false;
instance_activate_all(); //Activate all the objects
audio_resume_all(); //Activate all sounds
instance_destroy();
with pause_menu
{
instance_destroy();
}
}
}

Other Event: Room End:
execute code:

///Destroy surface

surface_free(surf_pause);

Draw Event:
execute code:

///Draw the surface

if(surface_exists(surf_pause))
{
draw_enable_alphablend(false);
draw_surface(surf_pause, view_xview[0], view_yview[0]);
draw_enable_alphablend(true);
}
else
{
surf_pause = surface_create(view_wview[0], view_hview[0]);
}

Draw GUI Event:
execute code:

///Draw background

var c_last = draw_get_color();;
//Draw semitransparent square
draw_set_color(c_black);
draw_set_alpha(0.5);
draw_rectangle(0,0, gui_width, gui_height,0);
draw_set_alpha(1);
draw_set_color(c_last);

Object that will perpare and create the pause menu..

Information about object: obj_pause_menu
Sprite:
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

///Initialize Variables For Menu

//Application surface size
var view_width = view_wview[0];
var view_height = view_hview[0];

//coordinates for drawing
xpos = floor(view_xview[0] + view_width*0.5);
ypos = floor(view_yview[0] + view_height*0.5);

//Buttons first
instance_create(xpos, ypos - 24, obj_pause_menu_b0);

instance_create(xpos, ypos + 24, obj_pause_menu_b1);

//Create the menus
menu_sys = instance_create(xpos, ypos - 48, obj_menu_control);

show_message('pause buttons created');

Destroy Event:
execute code:

///When menu obj is destroyed

//Destory the menu control

with menu_sys
{
instance_destroy();
}

//Destroy Buttons

with obj_pause_menu_b0
{
instance_destroy();
}

with obj_pause_menu_b1
{
instance_destroy();
}
 

jo-thijs

Member
In the alarm 1 event of obj_pause, you've got the wrong order of arguments here:
Code:
instance_create(obj_pause_menu, x, y);
Does fixing this solve the issue?
If not, are you sure obj_pause_menu is actually being created?
The create event should be performed anyway if the object gets created.
 
Top