Thursday, 16 June 2016

Week 10 - Production Part 4

Unit 8


Tutorial used:

Transitions


In my game I wanted to have it fade in-between the different rooms, this would make the transitions seem smoother and look more professional than a quick snap to new room.


To begin I created a new object and named it fadetogame_obj. This would be the object that causes the game to fade into a new room, specifically into the game. This object required two events, one Create Event and a Draw Event. Also note that I have checked the persistent box. This means that the object will travel into the next room and will only go away if a command tells it to.


First I needed to set up some variables, so I opened up a draw event and added two variables.

//fade to black
a = 0;
fade = 1;
These don't mean anything on their own, other than telling the game that these words are equal to the set variables.


Next I open up a draw event. This is what will make the transition work, by using the variables from the create event. It basically works by creating a black box fade in and out while the game changes rooms.

a = clamp(a + (fade * 0.05),0,1);
This is telling the game that the value of a will increase using the set calculation. Due to the fade variable being 1,  the value of a will increase.

if (a == 1)
{
      room_goto(overworld_rm);
      fade = -1;
}
This is telling the game that if a is equal to 1 then go to the set room and change the fade variable to -1. Changing the fade variable to -1 will cause the screen to clear until the black box is invisible.

if (a== 0) && (fade == -1)
{
      instance_destroy();
}
This is telling the game that if a is equal to 0 then destroy the object. This will remove the object from the game until it is called upon again.

draw_set_colour(c_black);
Sets the colour of the rectangle to black

draw_set_alpha(a);
Sets the alpha of the rectangle to equal the a variable.

draw_rectangle (
      view_xview[0],
      view_yview[0],
      view_xview[0] + view_wview[0],
      view_yview[0] + view_hview[0],
      0
This tells the game to make the rectangle the same size as the players view.

)
draw_set_alpha(1);
This sets the alpha so it can be changed.

By changing the goto room parts in the code to the room that you want to go to, it allows you to simply duplicate the object to work for any room transition that I want. To make this work I simply add some code to certain actions that spawn the object in the room. The object will then perform the transition before destroying the object.



No comments:

Post a Comment