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

pixeltroid

Member
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?
 
A

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:

 

pixeltroid

Member
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:

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
//initialize the door
new_x = 0;
new_y = 0;
new_room = noone
create event for door

//initialize the door
new_x = 0;
new_y = 0;
new_room = noone
create event for door

//initialize the door
new_x = 0;
new_y = 0;
new_room = noone

collision between player and door
//go thru the door
if (room_exists(other.new_room)) {
room_goto(other.new_room);
x = other.new_x;
y= other.new_y; }
In the map, for room1, I added a creation code for my door specifying where I spawn in room2
new_room = room2;
new_x = 384
new_y = 320

And I added this creation code for the door in room2, that puts me back into room1.
new_room = room1
new_x = 1504
new_y = 480
With these in mind, how do I cause rooms to fade from black when I enter them
 
A

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.
 

pixeltroid

Member
Easy!
Add this code in create event:
Code:
disappear = 0
alpha = 1
alarm[0] = 2
and then add this code in alarm0:
Code:
disappear = 1
and then add this code in step event:
Code:
if disappear = 1 then {
if alpha > 0 then {
    alpha -= 0.05
}}
The code above is fading out, Change the alpha > 0 to alpha < 1 to make it fade in and change alpha -= 0.05; to alpha += 0.05; to make it fade in.
and then add this code in Draw event:
Code:
draw_set_alpha(alpha)
draw_set_color(c_black)
draw_rectangle(0,0,room_width,room_height,false)
draw_set_alpha(1)
and that is it :D all the FADING IN and FADING OUT are in step event.
thanks. I add these in the new object for "fade", right?
 
R

Rusty

Guest
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.
 

LanNet

Member
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...)
 

c023-DeV

Member
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...)
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) )
 

LanNet

Member
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!
 
I

iDG27

Guest
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)
 
@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?).
 
I

iDG27

Guest
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)
 
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 }
 
Top