Jump to content


Photo
* * * * * 3 votes

Creating Your Own Room Transition With Gm7 Pro


  • Please log in to reply
38 replies to this topic

#1 torigara

torigara

    GMC Member

  • GMC Member
  • 6507 posts

Posted 02 March 2008 - 07:14 PM

  • 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
Introduction
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.
No need to afraid of "surface"; as to creating room transitions, you can simply think it as a sort of large sprite. The only difference is that you use functions like draw_surface instead of draw_sprite to draw it on the screen.

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.
Posted Image

Example:
// 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.

  • 2

#2 soccer99

soccer99

    Unschooled Developer

  • GMC Member
  • 524 posts

Posted 04 December 2008 - 02:24 AM

Wow this is awesome! I especially liked the 3rd example.
  • 0

#3 King Killa

King Killa

    <-- ?Which Way? -->

  • New Member
  • 572 posts

Posted 08 December 2008 - 05:28 AM

Very nice - informative and helpful. This should be a lot of help to me and many others.
  • 0

#4 2d_games

2d_games

    GMC Member

  • GMC Member
  • 1498 posts
  • Version:GM8

Posted 11 December 2008 - 12:05 AM

I liked it and understood just about all of it.(Everything except the surfaces.)

I do have one question though, when implementing the metroid style transition into my game, all but one thing confused me. TR_RIGHT and TR_LEFT. They are not part of GM's functions yet they light up as such. When I tried to use this in my game I got an error for an unknown variable.

I know why and its because when I put these into my game, it doesn't light up at all which clearly means I'm missing something improtant. What am I missing? Are you using an extention? Any scripts I left out other than enter_gate and scr_tr_gate?
  • 0

#5 xot

xot

    GMC Dismember

  • GMC Elder
  • 4775 posts
  • Version:GM:Studio

Posted 11 December 2008 - 12:35 AM

I do have one question though, when implementing the metroid style transition into my game, all but one thing confused me. TR_RIGHT and TR_LEFT. They are not part of GM's functions yet they light up as such. When I tried to use this in my game I got an error for an unknown variable.


Those are constants that torigara sets in "Global Game Settings".
  • 0

#6 2d_games

2d_games

    GMC Member

  • GMC Member
  • 1498 posts
  • Version:GM8

Posted 11 December 2008 - 12:39 AM

I do have one question though, when implementing the metroid style transition into my game, all but one thing confused me. TR_RIGHT and TR_LEFT. They are not part of GM's functions yet they light up as such. When I tried to use this in my game I got an error for an unknown variable.


Those are constants that torigara sets in "Global Game Settings".


EDIT:I fixed it and got it working now.

Edited by gamemakernooby, 11 December 2008 - 08:26 PM.

  • 0

#7 Very Melon

Very Melon

    GMC Member

  • New Member
  • 118 posts

Posted 11 December 2008 - 08:22 PM

This is an excellent example, it's really helpful when there are examples made which explain the less used actions of GM.

~Very Melon
  • 0

#8 conman124

conman124

    The Almighty!

  • New Member
  • 282 posts

Posted 12 December 2008 - 02:47 AM

Very nice! I didn't really understand the room transitions until this.

Thank you,
Conman124
  • 0

#9 Broxter

Broxter

    Jack Brockley

  • GMC Member
  • 540 posts
  • Version:GM:Studio

Posted 19 December 2008 - 10:29 AM

Wow, are we free to use the cool effects in the second example?

- Broxter
  • 0

#10 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • GMC Elder
  • 9328 posts
  • Version:Unknown

Posted 22 December 2008 - 08:04 AM

Nice ones :unsure: . One thing I don't understand, though. In your Metroid example, you reference the global variables gate_x[1] and gate_y[1] a few times. However, I can't for the life of me find where they are set. I tried searching in scripts for it, looked through the object codes, but I couldn't find it. I'm now pulling my hair out trying to understand how a variable that was never set could be referenced, and everything works fine.

Obviously I'm missing something...mind telling me what it is :P ?

-IMP ;) :)
  • 0

#11 2d_games

2d_games

    GMC Member

  • GMC Member
  • 1498 posts
  • Version:GM8

Posted 22 December 2008 - 11:49 PM

Nice ones :unsure: . One thing I don't understand, though. In your Metroid example, you reference the global variables gate_x[1] and gate_y[1] a few times. However, I can't for the life of me find where they are set. I tried searching in scripts for it, looked through the object codes, but I couldn't find it. I'm now pulling my hair out trying to understand how a variable that was never set could be referenced, and everything works fine.

Obviously I'm missing something...mind telling me what it is :P ?

-IMP ;) :)


In the enter_gate script, near the top, it declares some variables:

global.gate_x[0] = argument1.x;
global.gate_y[0] = argument1.y;

Edited by gamemakernooby, 22 December 2008 - 11:49 PM.

  • 0

#12 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • GMC Elder
  • 9328 posts
  • Version:Unknown

Posted 23 December 2008 - 05:43 AM

Yes, that sets gate_x[0] and gate_y[0]. But where are gate_x[1] and gate_y[1] set?


-IMP :D ;)
  • 0

#13 torigara

torigara

    GMC Member

  • GMC Member
  • 6507 posts

Posted 19 January 2009 - 01:33 PM

But where are gate_x[1] and gate_y[1] set?

They're set in the room start event of the player.

When a room transition takes place, GM preliminarily executes the create, room start and draw events in the next room to prepare the image. The example uses it to get the position of the exit.
  • 0

#14 Malkierian

Malkierian

    GMC Member

  • New Member
  • 12 posts

Posted 23 March 2009 - 04:42 AM

This really is helpful, but a few questions.

First, where are the arguments set for the transitions (i.e., where are the transition scripts called from in the first place where you set the surfaces? I just don't understand how to tell it what the surfaces are that it's using for the transitions)?

Second, should I be able to do a Super Mario Bros 3 type transition (where it sets pixels to black in a clockwise spiral from the outside to inside) in one transition or would I have to use two?
  • 0

#15 Squiggy2

Squiggy2

    GMC Member

  • New Member
  • 159 posts

Posted 13 April 2009 - 12:32 AM

I love this example it helped me so much, I cannt downlaod any extensions so im am so glad there is another way :P :P ;) :P :P
  • 0

#16 p@lik

p@lik

    GMC Member

  • GMC Member
  • 115 posts

Posted 18 April 2009 - 03:16 AM

sweet i like number 3
  • 0

#17 Yambam

Yambam

    GMC Member

  • GMC Member
  • 630 posts
  • Version:GM8

Posted 23 April 2009 - 07:30 PM

i dont get how to make that gate transion but i want to use it ;)
  • 0

#18 Titanium

Titanium

    the perfectionist

  • GMC Member
  • 1138 posts

Posted 01 September 2009 - 12:57 AM

I must say this is the best Transition Tutorial. It works perfectly without glitches, AND, it's very informative. I love it. 100/10!!! I love the comments... seriously... You have more comments than actual code which is pretty helpful.
  • 0

#19 Itachifan

Itachifan

    GMC Member

  • GMC Member
  • 765 posts
  • Version:GM8

Posted 15 October 2009 - 01:55 AM

Darn, this looks so cool. If only it was for unregistered.

Anyways, do you think a room transition like this one could be made?


(In 0;32 and in 5:59)



http://www.youtube.c...feature=related
  • 0

#20 pikachu123

pikachu123

    Pika, pika, pikachu!

  • GMC Member
  • 580 posts
  • Version:GM8

Posted 13 February 2010 - 07:07 PM

I do have one question though, when implementing the metroid style transition into my game, all but one thing confused me. TR_RIGHT and TR_LEFT. They are not part of GM's functions yet they light up as such. When I tried to use this in my game I got an error for an unknown variable.


Those are constants that torigara sets in "Global Game Settings".


EDIT:I fixed it and got it working now.

How did you type the TR_LEFT and the TR_RIGHT etc. in? it won't let me
Nvm figured it out

Edited by pikachu123, 13 February 2010 - 07:10 PM.

  • 0

#21 Bjornacorn

Bjornacorn

    World of Warcraft

  • New Member
  • 197 posts

Posted 06 July 2010 - 07:49 AM

I've always wondered if this was possible. Thank you, torigara. You walkthrough made sense to me.
  • 0

#22 imam_mashur

imam_mashur

    GMC Member

  • New Member
  • 282 posts

Posted 11 November 2010 - 10:24 AM

AWESOME...
5/5

  • 0

#23 Wooderson

Wooderson

    GMC Member

  • New Member
  • 2 posts

Posted 17 November 2010 - 02:15 AM

how do I create a new room with this? cause every time i try it says the room doesn't exist... am i missing something?, or can i only work with the previously created rooms?
  • 0

#24 torigara

torigara

    GMC Member

  • GMC Member
  • 6507 posts

Posted 19 November 2010 - 02:50 AM

how do I create a new room with this? cause every time i try it says the room doesn't exist...

Supposing that you're using the third example, every room should contain an instance of obj_controller. In the room editor, hold Ctrl and right-click the instance, choose "Creation Code", and you will see a piece of code that looks like following.
// Set indices of room at four sides (see do_transition)
tr_room[TR_LEFT] = room_east;
tr_room[TR_RIGHT] = room_west;
tr_room[TR_UP] = room_north;
tr_room[TR_DOWN] = room_south;
You're supposed to specify the next room at each side in this way. (Take a look into the script do_transition for further description.)
  • 0

#25 WannabeGod

WannabeGod

    GMC Member

  • New Member
  • 2 posts

Posted 19 November 2010 - 09:40 AM

where are the arguments set for the transitions (i.e., where are the transition scripts called from in the first place where you set the surfaces? I just don't understand how to tell it what the surfaces are that it's using for the transitions)?

You don't need to set them, gamemaker inputs the surfaces of the old and new room in the transition script.
All the arguments are actually predefined and thrown in by gm.

Edited by WannabeGod, 19 November 2010 - 09:42 AM.

  • 0

#26 goldage5

goldage5

    GMC Member

  • GMC Member
  • 152 posts

Posted 23 December 2010 - 05:25 PM

link broken!!!!!
  • 0

#27 shilohbrown

shilohbrown

    GMC Member

  • New Member
  • 1 posts

Posted 13 January 2011 - 02:02 AM

The ninja got closer and cuborm a blast got the ninja.
  • 0

#28 Robert3DG+

Robert3DG+

    Designer

  • GMC Member
  • 1925 posts
  • Version:GM:Studio

Posted 13 January 2011 - 04:10 AM

Link is indeed down. Posted Image
  • 0

#29 Pro Pro.

Pro Pro.

    GMC Member

  • GMC Member
  • 734 posts

Posted 14 January 2011 - 06:03 AM

can someone re-upload this, or pm me if you have the files? Its the only custom transition example i can find.
  • 0

#30 Slajmboll

Slajmboll

    GMC Member

  • GMC Member
  • 71 posts
  • Version:GM:Studio

Posted 20 March 2011 - 11:31 PM

Hello you all. I'm kinda having trouble with this (I also recently started to use GM, so that makes sense I guess). :)

Anyhow, I'm getting this message when going to the right border of the screen:

"ERROR in
action number 4
of Keyboard Event for <Right> Key
for object kara:

In script do_transition:
Error in code at line 11:
next_room = obj_controller.tr_room[argument0];
^
at position 14: Unknown variable obj_controller
"


My creation code in the room seems ok I think (only want one entrance, to the right):

"// Set indices of room at four sides (see do_transition)
tr_room[TR_LEFT] = -1;
tr_room[TR_RIGHT] = rm_room0;
tr_room[TR_UP] = -1;
tr_room[TR_DOWN] = -1;"


Information about object:

Sprite: character
Solid: false
Visible: true
Depth: 0
Persistent: true
Parent: <no parent>
Mask: <same as sprite>

Step Event:
if relative position (0,1) is collision free for Only solid objects
set the gravity to 0.5 in direction 270
else
set the gravity to 0 in direction 270
if vspeed is larger than 12
set the vertical speed to 12

Collision Event with object wall:
move in direction direction at most 12 till a contact with solid objects
set the vertical speed to 0


Keyboard Event for <Left> Key:
if relative position (-4,0) is collision free for Only solid objects
jump relative to position (-4,0)

Keyboard Event for <Up> Key:
if relative position (0,1) gives a collision with Only solid objects
set the vertical speed to -10

Keyboard Event for <Right> Key:
if relative position (4,0) is collision free for Only solid objects
jump relative to position (4,0)
if object is aligned with grid with cells of 0 by 32 pixels
execute code:

if (x+32 >= room_width) {
// Go to the room to the right when the player tries to go beyond the right border of the room
do_transition(TR_RIGHT);
}
else {
hspeed = 4;
vspeed = 0;
}


I have no clue, is there something specifik I should change in the scripts? I deleted the teleportscript, gatescript and font, since I didnt have use for it. Hmm. Anway, I would be so thankful for some help. I offer cake and love. And sorry for my crappy english.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users