PDA

View Full Version : Room Transitions



WhyidiE
April 23rd, 2010, 02:41 PM
Hi, im struggiling to find any information regarding a character making the transitions between one room to another simply by walking to the edge of the stage.

The game itself requires the character to be controlled via the keyboard, walk to a door, an animation to occur once the door is clicked and the character walk into it, appearing in the next room!

So far i've made each room into a movie file, placed them each into one frame, made sure that the command stop(); is in place.

any suggestions would be extremely appreciated at this point :)

dandylion13
April 23rd, 2010, 03:21 PM
Hello, and welcome to Kirupa!

So, you have a different MovieClip object for each room?

I assume you're adding them to the stage with addChild, like this:

addChild(room_1);

If you are, you can add a new room and remove the previous one when the player gets to the edge of the stage or a door, like this:

addChild(room_2);
removeChild(room_1);

Or... did I misread your post?
Are all your rooms in one single MovieClip, each placed on a different frame?

Also, I assume you're using AS3.0, and that you already know how to move a character around the stage with the keyboard and are listening to mouse events when a door is clicked?

WhyidiE
April 26th, 2010, 06:16 AM
Thanks for the welcome! :)

Yes they are on an action layer, with each one in a frame as an MovieClip ^^, so they are already on the stage. The problem i have is i can only use AS3 in a basic fashion :( silly i know

The problem is, is where do i place those events for the room change, and do i use addChild(room_1) etc when i want to change room?

plablugoo
April 30th, 2010, 11:43 PM
what about this code
http://www.emanueleferonato.com/2006/12/31/flash-game-creation-tutorial-part-5/

you have to get to level 3 and 4 to see room transitions

dandylion13
May 1st, 2010, 10:06 AM
If all your rooms are on frames inside one MovieClip, you just need to use one line of code in this format:

movieClipInstanceName.gotoAndStop(roomNumber);

As for where to place it, you'll have to decide what events in your game cause the room to change.

Do you understand basic collision detection using hitTestObject and how to check for screen boundaries?

WhyidiE
May 4th, 2010, 10:49 AM
Well I am pretty new to coding in Flash, only problem is that I have had to revert to AS 2.0 not 3.0 so if there are any sites similar to the one posted that will work for that coding that would really help!

I'm able to grasp hitTestObjects at the moment yes ^^

dandylion13
May 4th, 2010, 02:59 PM
That line of code I posted above will still work with AS2.0 :)

WhyidiE
May 5th, 2010, 04:02 PM
That line of code I posted above will still work with AS2.0 :)

This has really helped :) one more question, if i want the character to be at a certain point in the next room after entering it, what code would i need, i dont want him in like the top corner or directly in the centre but right next to the entrance/exit! :)

dandylion13
May 5th, 2010, 04:20 PM
Set it's x and y properties to the x and y position on the stage where you want it to be.
Do you know how to do this?

WhyidiE
May 5th, 2010, 04:31 PM
No i don't hehe, im such a noob :P your input has been great so please continue! :D

My characters code so far!:

_root.attachMovie("character","char",_root.getNextHighestDepth());
char.xSpeed = 0;
char.ySpeed = 0;
char.onEnterFrame = function() {
if (Key.isDown(Key.UP)) {
trace("UP");
this.ySpeed = -2;
} else if (Key.isDown(Key.DOWN)) {
trace("DOWN");
this.ySpeed = 2;
} else {
this.ySpeed = 0;
}
if (Key.isDown(Key.LEFT)) {
trace("LEFT");
this.xSpeed = -3;
} else if (Key.isDown(Key.RIGHT)) {
trace("RIGHT");
this.xSpeed = 3;
} else {
this.xSpeed = 0;
}
if (this.xSpeed == 0 && this.ySpeed == 0) {
this.walk.gotoAndStop("stand");
}
if (this.xSpeed>0) {
char.gotoAndStop("right");
} else if (this.xSpeed<0) {
char.gotoAndStop("left");
} else if (this.ySpeed>0) {
char.gotoAndStop("down");
} else if (this.ySpeed<0) {
char.gotoAndStop("up");
}
this._x += this.xSpeed;
this._y += this.ySpeed;

if (_root.corr1.hitTest(this)) {
_root.gotoAndPlay(2);

}
};

dandylion13
May 5th, 2010, 05:34 PM
Is this the code that handles the room transition?

if (_root.corr1.hitTest(this))
{
_root.gotoAndPlay(2);
}

if it is, you can add the character's new x and y position like this:

if (_root.corr1.hitTest(this))
{
_root.gotoAndPlay(2);
this._x = 0;
this._y = 0;
}

This will place it in the top left corner of the stage. You'll need to experiment with those numbers to find the correct new position.

WhyidiE
May 6th, 2010, 08:45 AM
I've taken the code for handiling the character transition out, the hitTest boxes on the levels are the ones used for the character transition now, the

this._x = 0;
this._y = 0;
}

just makes the character jump back to his starting position when he tries to enter another frame :(

dandylion13
May 6th, 2010, 02:24 PM
Yes, you need to use the x and y co-ordinates of the stage position where you want him to appear. I'm not sure what those numbers will be for your game.