Drawing a black screen then getting rid of it[SOLVED]

Hello

I draw a black screen in my game that covers the entire room and objects to create a curtain effect, which I then went to be removed revealing the room with different objects in different positions.

However, I want there to be a delay between drawing and removing. I realise you can't put an alarm in a draw event (or at least, it's ineffective), but I have also tried a flag to trigger an alarm in the step event but it doesn't seem to work.

Here is my draw event code:
if dark==1{
draw_set_color(c_black);
draw_set_alpha(1)
draw_rectangle(0,0,room_width,room_height,0);
instance_create_depth(486,59,-950,obj_top_hat_face_only)
instance_create_layer(544,288,"instances",ob_pl_UM_glasses)

}

I tried to put a flag at the end of the code (dark2=1) then trigger an alarm in the step event (if dark2=1{alarm[0]=60} but it had no effect.

Any help would be appreciated.
 
//before you draw your rectangle
Draw_set_alpha(timer/100);

//create event
timer = 100;

//step event:
If timer > 0
{timer--;}


This will create a fade in effect. If it is too fast try timer-=0.1 or smaller.

EDIT: yeah, don't create objects in the draw event.
 
Last edited:

Vishnya

Member
You create two objects every step in draw event when variable "dark" is equal true? Not shure that it is good solution.

Try to fix code like this:
Code:
if dark>0
{
    draw_set_alpha(dark)
    draw_rectangle(view_xview, view_yview, view_xview+view_wview, view_yview+view_hview)
    draw_set_alpha(1)
    dark-=1/room_seed
}
 
Last edited:

Paskaler

Member
Without any dark variables you could try doing this:
  • In the create event set alarm[0] = 60
  • Keep all of the code you have in the draw event, but without the if statement and the code that creates instances
  • In the step event put:
Code:
if alarm[0] <= 0 {
   // the code that destroys instances here
   instance_destroy();
}
Note: There won't be any smooth fading with this code, the screen will turn black, after a second(if your game speed is set to 60), it will simply vanish and the instances will be created.
 

TheouAegis

Member
You don't want two new instances just for hat and glasses, just draw their sprite(s) using draw_sprite().

If you don't mind having no fading, set an alarm you aren't using (i like alarm 11 myself) to however long you want the black screen to be up, then in the Draw End event put

Code:
if alarm[11] {
draw_clear(0);
draw_sprite(spr_top_hat_face_only, 0,486,59);
draw_sprite(spr_pl_UM_glasses, 0, 544,288);
}
Then make sure you have an alarm event so it counts down ir ir ually tick it down yourself.
 
//before you draw your rectangle
Draw_set_alpha(timer/100);

//create event
timer = 100;

//step event:
If timer > 0
{timer--;}


This will create a fade in effect. If it is too fast try timer-=0.1 or smaller.

EDIT: yeah, don't create objects in the draw event.
This works, but t's not the effect I wanted. My player chooses an option which triggers the black screen, then after five seconds, I want the screen to instantly disappear, not fade out.
 
Without any dark variables you could try doing this:
  • In the create event set alarm[0] = 60
  • Keep all of the code you have in the draw event, but without the if statement and the code that creates instances
  • In the step event put:
Code:
if alarm[0] <= 0 {
   // the code that destroys instances here
   instance_destroy();
}
Note: There won't be any smooth fading with this code, the screen will turn black, after a second(if your game speed is set to 60), it will simply vanish and the instances will be created.
Tried this, screen just stayed black, didn't disappear.

CODE CREATE:
alarm_set(0, 60);
depth=-900
CODE STEP:
if alarm[0] <= 0 {
instance_destroy();
}
CODE DRAW:
draw_set_color(c_black);
draw_set_alpha(1)
draw_rectangle(0,0,room_width,room_height,0);

When I kept the variable dark and put it to 0 in the draw event, it created the effect but I needed to be a few seconds longer.
 
D

DarthTenebris

Guest
Trigger:
Code:
black = true;
alarm[0] = 5 * room_speed;
Alarm[0]:
Code:
black = false;
Draw:
Code:
if (black) {
     draw_set_color(c_black);
     draw_set_alpha(1);
     draw_rectangle(0, 0, room_width, room_height, false);
}
Hope I helped :)
 
Trigger:
Code:
black = true;
alarm[0] = 5 * room_speed;
Alarm[0]:
Code:
black = false;
Draw:
Code:
if (black) {
     draw_set_color(c_black);
     draw_set_alpha(1);
     draw_rectangle(0, 0, room_width, room_height, false);
}
Hope I helped :)
Thank you; this works. If I want certain things to happen after the black screen disappears, I would just put it in the step event:
Step:
Code:
if black = false{instance create etc};
 
Top