GameMaker Background image of a room doesn't "fade" after applying alpha

Enlapse

Member
Hello there!

Before I start, here is what I am using to test this at the moment:
OS: Windows 10 PRO 1909 (18363.836)
Game Maker Studio: 2.2.5.481
Runtime: 2.2.5.378

And I think that's all that may be relevant.

So, after using the code below to change the background image's alpha of a room called "room_gameStart" (the first room to appear in game after pressing F5) from 1 (by default) to 0 applying an alpha reduction of 0.01 per step, and game is running at 60 steps per second (60 fps), so the background alpha change should take about a 1.67 seconds to go from totally visible (alpha = 1) to totally invisible (alpha = 0), but even if the alpha is being reduced every step, the background image doesn't do the "fade" effect it should and stay as visible as the beginning (like alpha = 1 ).

I have a debug message show every step with the current alpha of the background and shows that each step is being reduced successfully by 0.01, so the script works as intended but the image doesn't change.

I have an object called "obj_gameStart_to_titleScreen" which has two events:
- A CREATE event with this code:
GML:
/// @description
fadeSpeed = 0;
- A STEP event with this code:
GML:
if ( keyboard_check( vk_enter ) && fadeSpeed == 0 ) {
    fadeSpeed = 0.01;
}

var layerId = layer_get_id("Background");
var backgroundId = layer_background_get_id(layerId);
var bgCurrentAlpha = layer_background_get_alpha(backgroundId);

if ( bgCurrentAlpha > 0 ) {
    layer_background_alpha(backgroundId, bgCurrentAlpha - fadeSpeed);
}

show_debug_message(bgCurrentAlpha);
This object is placed in the center of the room "room_gameStart" (the only room I have for now), and the background layer of the room is named "Background", and it indeed has an sprite associated.

And thats all I think I can say. If you have any doubts, please, let me know, thank you!
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Do you have another background UNDER this one in the room that draws a background colour? If not then you should, as what is probably happening is that the background is being drawn to the back buffer, which then isn't being cleared, so even though the background alpha is going down, it's just being drawn over the original image as it is on the back buffer.

So, add another layer to your room and set to simply the colour black and put it under the background that you are lowering the alpha of.
 

Enlapse

Member
Do you have another background UNDER this one in the room that draws a background colour? If not then you should, as what is probably happening is that the background is being drawn to the back buffer, which then isn't being cleared, so even though the background alpha is going down, it's just being drawn over the original image as it is on the back buffer.

So, add another layer to your room and set to simply the colour black and put it under the background that you are lowering the alpha of.
Okay, first of all, thank you for the fast reply.

Now, yes, this did the trick, I needed to place a background with just the colour (in this case black), to make the background image "fade" out.

Thank you very much!
 
Top