Smooth fade in/out for background change

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.
 

THE_T_V1RUS

Member
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.
 
T
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.
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?
 

THE_T_V1RUS

Member
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]);
I'm not sure, but it could be you have

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