Please tell me how to make a fade transition between rooms.

Discussion in 'Programming' started by pixeltroid, Jul 23, 2016.

  1. pixeltroid

    pixeltroid Member

    Joined:
    Jul 23, 2016
    Posts:
    653
    I'm a complete noob to programming and I've been using gamemaker for less than a week now. So far, I have figured out character movement, basic enemy AI, room changes, level design and sprite animations. I can confidently say that my first game is taking shape pretty well.

    However, for the last 2 days, I've been trying to create a simple fade transition as I change rooms and this has got to be the most difficult thing to achieve. How can such a simple thing be so difficult!?

    All I need is to have the room fade in from black when it starts. Can I PLEASE get step by step instructions and the code that I can simply copy paste into my project?
     
  2. Aura

    Aura Guest

    Welcome to the GMC! ^^

    Since this a programming question and not a game design or development query, let's get this moved to the Programming forum.

    Either way, this tutorial might be what you have been looking for:

     
  3. pixeltroid

    pixeltroid Member

    Joined:
    Jul 23, 2016
    Posts:
    653
    Thanks. I did exactly as instructed in the video but I kept getting an error message. I couldn't get it to sync with my room change codes

    This is what I've been using

    create event for door

    collision between player and door
    In the map, for room1, I added a creation code for my door specifying where I spawn in room2

    And I added this creation code for the door in room2, that puts me back into room1.
    With these in mind, how do I cause rooms to fade from black when I enter them
     
  4. Aura

    Aura Guest

    Please post the error message that you're getting and how you implemented that; post all the code that you're currently using.

    Either way, @KingdomOfGamez's method should work too.
     
  5. pixeltroid

    pixeltroid Member

    Joined:
    Jul 23, 2016
    Posts:
    653
    thanks. I add these in the new object for "fade", right?
     
    KingdomOfGamez likes this.
  6. Rusty

    Rusty Member

    Joined:
    Jun 21, 2016
    Posts:
    198
    All you need to do is set a custom timer.
    Code:
    //(changing rooms)
    variable_timer=30;
    
    Step Event:
    variable_timer-=1;
    
    Draw Event:
    draw_set_alpha(variable_timer/30);
    draw_rectangle(view_xview,view_yview,view_xview+view_wview,view_yview+view_hview);
    All you need to do is "(1-(varialbe_timer/30))" to fade rooms in instead.

    Edit:
    I want to point out that "view_xview" and "view_yview" are only important if you are using views. These built in variables keep track of the top left hand corner of the screen so that the fade effect will always be draw relative to the section of the room being currently shown on the screen by the view.
     
    molcap and pixeltroid like this.
  7. pixeltroid

    pixeltroid Member

    Joined:
    Jul 23, 2016
    Posts:
    653
    Yes! It worked! Thanks a lot man!
     
    KingdomOfGamez likes this.
  8. pixeltroid

    pixeltroid Member

    Joined:
    Jul 23, 2016
    Posts:
    653
    Thanks Rusty. Appreciate your input. But I implemented KingdomofGamez's method and it worked! :)
     
    KingdomOfGamez likes this.
  9. LanNet

    LanNet Member

    Joined:
    Jul 29, 2017
    Posts:
    31
    Excuse me. I have used this code to make room transition.
    if disappear = 1 then {
    if alpha > 0 then {
    alpha -= 0.05
    }
    }

    draw_set_alpha(alpha)
    draw_set_color(c_black)
    draw_rectangle(0,0,room_width,room_height,false)
    draw_set_alpha(1)

    But it appears that my font score(which is persistent) also turned into black color. Any suggestion to deal this problem? (sorry for posting old thread...)
     
  10. c023-DeV

    c023-DeV Member

    Joined:
    Nov 23, 2016
    Posts:
    54
    Depends in what event and at what depth/order you draw your score and the fade effect?
    If you draw your score with a drawGUI event then it should be visible above all regular drawn pixels.
    (be aware that draw GUI needs some setting up: that the x and y in drawGUI are screen coordinates and set: display_set_gui_size(YOURRESOLUTION) )
     
  11. LanNet

    LanNet Member

    Joined:
    Jul 29, 2017
    Posts:
    31
    I think it was because of the drawGUI event. To make it easy, i just add destroy instance after animation end in obj_transition. So the black color will disappear(my own solution). By the way, thanks_for_the_reply!
     
  12. iDG27

    iDG27 Member

    Joined:
    Jan 13, 2019
    Posts:
    5
    if disappear = 1 then {
    if alpha > 1 then {
    alpha += 0.05
    }}

    I made what you said to fade in but it seems not working.
    It turns only black without any animation.
    (sorry for being late)
     
  13. RefresherTowel

    RefresherTowel Member

    Joined:
    Jul 13, 2016
    Posts:
    1,210
    @iDG27 Look at your code and look at LanNet's code again. He has if alpha > 0 while you have if alpha > 1. However, there's a few things that could be tweaked. Disappear is supposed to be a boolean value (i.e. true or false) so you should actually use true and false and not 1 and 0. This is a common rookie coding mistake, but you should always use numbers for numbers, and booleans for booleans. Also, single equals (=) is for SETTING something to a value, whereas double equals (==) is used for COMPARING values. GameMaker will let you get away with using a single equals for comparison, but it is a terrible habit to get into, so you should try do it the proper way.

    Also, @LanNet, the reason that your score text was turning black is because whenever you set a colour with draw_set_colour() that colour applies globally until it is set again. I'm pretty certain that you mustn't be setting draw_set_colour() to the colour you want your score to be drawn in the code chunk where you are drawing your score. So a better fix would be simply to set the draw colour in the code that you draw your score as well. Destroying the obj_transition object might work, but it's better to understand WHY it's happening (what if you set a colour in an instance you don't want to destroy?).
     
  14. iDG27

    iDG27 Member

    Joined:
    Jan 13, 2019
    Posts:
    5
    What? Wait, no. I wanted to fade in, not fade out. but it seems not working as it was said up there.
    (I just started programming, sorry for that dumb questions)
     
  15. EvanSki

    EvanSki King of Raccoons

    Joined:
    Apr 17, 2018
    Posts:
    575
    @ShaunJS

     
  16. RefresherTowel

    RefresherTowel Member

    Joined:
    Jul 13, 2016
    Posts:
    1,210
    Even if you were trying to fade in, your code said (in laymans terms): "If I am fully opaque and have no transparency, then increase my opaqueness." That makes no sense. It should have been if (alpha < 1) { alpha += 0.05 }
     

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