GMS 2.3+ Fade Transition Not Drawing First Part

T2008

Member
When the player dies, it creates a room transition which draws a red fade over the screen and then goes to title screen with a black fade. The second part works right, but it won't draw the first red part. I have no idea why? Any insights would be greatly appreciated!

Create Event:
Code:
global.control_lock = true;

instance_deactivate_all(true);
 
//Fade Variables
fade_alpha = 0;
fade_state = 1;//1 or -1, ie whether fading in or out
fade_speed = 0.02; //0.0025;

//Initialize Room Specific Variables
room_go_to = rm_frontend_rm2;
Draw Event:
Code:
fade_alpha = clamp(fade_alpha + (fade_state * fade_speed),0,1);   //0 and 1 are minimum and maximum number of clamp
if (fade_alpha == 1) {  //when this has happened up to 1, go to next room
    room_goto(room_go_to); 
    fade_state =-1;
}

if (fade_alpha == 0) && (fade_state == -1) {
    instance_destroy();
}

//Draw Rectangle
var _xx = camera_get_view_x(view_camera[1]);
var _yy = camera_get_view_y(view_camera[1]);
var _Width = camera_get_view_width(view_camera[1]);
var _Height = camera_get_view_height(view_camera[1]);
if (fade_state >= 0) {
    draw_set_colour(c_red);
} else if (fade_state < 0) {
    draw_set_colour(c_black);
}
draw_set_alpha(fade_alpha);
draw_rectangle(_xx, _yy, _xx + _Width, _yy + _Height, false);
draw_set_alpha(1); //set it back
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
You say it doesn't draw the red rectangle, so what does it do? Does it just change room? Does it pause then change room? Does it draw anything? The code at first glance looks okay, so my recommendation would be to add a breakpoint into the draw event and run the game in the debugger... you can then step through the code a line at a time and check the values of the variables are what they should be. I suspect that the fade_state is being set to the wrong value somewher, but this way you can check.
 

T2008

Member
Thanks for the response. I ended up just creating a separate object to draw red screen first and it created the effect I wanted. I'll have to remember this debugger tip for future issues.
 
Top