1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

Smooth fade in/out for background change

Discussion in 'Programming' started by FloresSottile, Jul 13, 2019.

  1. FloresSottile

    FloresSottile Member

    Joined:
    Jun 1, 2019
    Posts:
    14
    I'm using GM 1.4 and I'd like to know if there's some cool way to change backgrounds by index without having them added in the room, because I'm trying to work with more than 8 backgrounds (which is how many one can add to the room) and my intention is to keep the same room for those backgrounds. My game changes the backgrounds by checking a condition and if so by setting background_index[0] to another background index (not added to the room) but the change is instant. I'd like to make it smooth.

    Any tip or tutorial to share? Thanks in advance.
     
  2. THE_T_V1RUS

    THE_T_V1RUS Member

    Joined:
    Jun 8, 2018
    Posts:
    9
    Look into the background_alpha function. You should be able to use this to fade the current background out, change backgrounds, and then fade the new background in.

    I personally would draw the background image manually using draw functions rather than actually setting a background.
     
  3. FloresSottile

    FloresSottile Member

    Joined:
    Jun 1, 2019
    Posts:
    14
    T
    That's a good idea.
    I would do that too, but it's kind of complicated since the background has been set to move through the screen.
    So I tested your idea by creating and object that I call "fader" but for some reason it fails to fade out one time, instead it fades it many times.

    This is the code I'm testing:

    Create Event
    Code:
    fade_in = false;

    Step Event
    Code:
    if(background_alpha[0] > 0 && !fade_in) // Fading out actual background.
        background_alpha[0] -= 0.01;
    
    
    if(background_alpha[0]  == 0) //Changing background and setting new background alpha
    {
        background_index[0] = bg_space2;
        fade_in = true;
        background_alpha[0] = 0.01;
    }
        
    if(background_alpha[0] > 0 && fade_in){ // Fading in next background.
        if(background_alpha == 1){
            instance_destroy(self);
        }
        else
            background_alpha[0] += 0.01;
    }
    
    show_debug_message(background_alpha[0]);
    The alpha goes down to 0 and then it starts adding up, but for some reason when it gets to 0.50 it gets stuck and I it fades in the next background way later than it should be. Is there something I'm missing about the Step event?
     
  4. THE_T_V1RUS

    THE_T_V1RUS Member

    Joined:
    Jun 8, 2018
    Posts:
    9
    I'm not sure, but it could be you have

    if(background_alpha == 1) instead of if(background_alpha[0] == 1)
     

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