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

Discussion in 'Programming' started by Mr Awesome, Jul 1, 2018.

  1. Mr Awesome

    Mr Awesome Member

    Joined:
    Dec 14, 2017
    Posts:
    122
    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.
     
  2. LucasTheNewbie

    LucasTheNewbie Member

    Joined:
    Oct 4, 2016
    Posts:
    284
    //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: Jul 1, 2018
    Mr Awesome likes this.
  3. Vishnya

    Vishnya Member

    Joined:
    Jul 6, 2016
    Posts:
    65
    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: Jul 2, 2018
    Mr Awesome likes this.
  4. Paskaler

    Paskaler Member

    Joined:
    Jul 4, 2016
    Posts:
    315
    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.
     
    Mr Awesome likes this.
  5. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,889
    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.
     
  6. Mr Awesome

    Mr Awesome Member

    Joined:
    Dec 14, 2017
    Posts:
    122
    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.
     
  7. LucasTheNewbie

    LucasTheNewbie Member

    Joined:
    Oct 4, 2016
    Posts:
    284
    Then say

    If timer <= 0
    {
    Draw_rectangle(Bla, Bla, Bla, Bla, bla);
    }
     
    Mr Awesome likes this.
  8. Mr Awesome

    Mr Awesome Member

    Joined:
    Dec 14, 2017
    Posts:
    122
    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.
     
  9. Fat_Man3468800

    Fat_Man3468800 Member

    Joined:
    Jun 22, 2016
    Posts:
    487
    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 :)
     
    Mr Awesome likes this.
  10. Mr Awesome

    Mr Awesome Member

    Joined:
    Dec 14, 2017
    Posts:
    122
    I'll try this, but why do I want to draw another rectangle? Should this go in the step event? I thought draw only goes in the draw event?
     
  11. Mr Awesome

    Mr Awesome Member

    Joined:
    Dec 14, 2017
    Posts:
    122
    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};
     
  12. LucasTheNewbie

    LucasTheNewbie Member

    Joined:
    Oct 4, 2016
    Posts:
    284
    No the if comes where you usually draw your black screen. No new rectangle
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice