- Title: Creating your own room transition with GM7 Pro
- Description: Describes how to define your own room transition script. The example file contains a number of sample scripts for basic and advanced effects.
- GM Version: GM7
- Registered: Yes
- File Type: .zip (containing three .gmk)
- File Size: 313K
- File Link: room_transition.zip
Game Maker 7 provides a way to define your own room transition effect. However, the explanation of the mechanism is very condensed (stuffed into the description of one function) and hard to get. This tutorial describes how to define a script and register it to be used on room transitions.
The first example contains scripts to emulate all of in-built room transitions (plus a few in the Room Transitions extension.) Not so impressive, but you can take basic expressions out of the code to implement your own effects. The second one contains a number of advanced sample scripts those also can be used as a base of your own one. The third example demonstrates other possibility of custom room transitions, such as keeping HUD and player on the screen during the transition. Useful on implementing so-called Zelda-style and Metroid-style room transitions.
Defining a script
At first, you have to define a transition script which is meant to be repeatedly called from Game Maker during the transition. The script is called with five arguments:
- argument0 is the surface with the image of the previous room.
- argument1 is the surface with the image of the next room.
- argument2 and argument3 are the width and height of the surface, respectively. (It is also the size of the drawing region.)
- argument4 is fraction of the transition. This takes a value between 0 and 1.
The last parameter, fraction, is the most important one. Your responsibility is to mix and draw those two images of rooms onto the screen according to the fraction. At the beginning (when fraction is 0) the first image should occupy the entire screen. As the transition goes on, the script is called over and over with gradually increasing fraction, to mix/interpolate/blend two images accordingly. At the end (when fraction is 1) the second image should occupy the screen.
// Script for "Squeeze from right" transition var s_prev, s_next, s_width, s_height, fraction; s_prev = argument0; // surface with the image of the previous room s_next = argument1; // surface with the image of the next room s_width = argument2; // the width of the surface s_height = argument3; // the height of the surface fraction = argument4; // fraction of the transition (between 0 and 1) // Draw the previous room stretched at the left side. // Its left position is fixed to 0, while width changes from s_width to 0. draw_surface_stretched(s_prev, 0, 0, s_width * (1 - fraction), s_height); // Draw the next room stretched at the right side. // Its left position changes from s_width to 0, while width changes from 0 to s_width. draw_surface_stretched(s_next, s_width * (1 - fraction), 0, s_width * fraction, s_height);(Also take a look into the game information of the first example; it describes the basic way to derive those expressions.)
Using the room transition
Next, you have to register the transition to the system, using the function transition_define.
transition_define(100, "scr_squeeze_right");Note that the second argument is the name of your script, which is a string. You usually have to put quotation marks around the name, as in the example above.
The first argument is the index which is to be assigned to the transition. You can use an arbitrary number unless it overlaps with an existing one. It is a good idea to define a constant for each kind of transition if you plan to make it an extension package.
Although it is harmless to register the same transition with the same index multiple times, you’d better ensure it to be registered only once throughout the game. (For example, execute the code in the game start event of a controller object.)
Once the transition is registered, you can use it by setting the index to transition_kind in prior to changing the room.
transition_kind = 100; // Squeeze from right room_goto_next();Additionally, you can change the speed of the transition with setting transition_steps. It controls how many times the script is called during transition. The larger the number is, the slower the transition gets and takes longer to complete. (With the default value of 80, it takes about 1.2 seconds.)
Link Updated: 6th Mar 2008
- Ripple effect is now less blocky
- added two sample effects
- some minor code refine for Metroid transition
Edited by torigara, 15 January 2011 - 04:30 PM.