Game Development Community

Switching two scenes in animation.

by yxm mac · in Torque Game Builder · 05/30/2011 (6:04 am) · 6 replies

Hello,

How to use animation to switch two scenes?
such as Cocos2d, transition two levels(scene), in animations ( fade in/out, left to rigt, etc...) ?

How the heck do I do it?

Thanks.

#1
05/31/2011 (12:15 pm)
Well actually never tried it but I have a Logo and a loading screen both with fade out and fade in transitions.

For that I used the following behavior:

http://www.garagegames.com/community/resources/view/17815

If you scroll through the code I'm pretty sure you'll find what you need.
Please tell me if this works for you. Otherwise I might have some other idea.

Regards,
Julian
#2
05/31/2011 (8:54 pm)
@Julian, Thank you for your suggestions.

I had a try, and that does not work for needed.

two game levels switching, two "t2dSceneWindow t2dSceneGraph", why no effect for fade in/out. but can set positions.

Regards.
#3
06/04/2011 (6:21 am)
I needed a fade out, fade in transition in my game, so I did the following:

in my two scenes i put a black polygon that covers the entire screen. make sure it is at the topmost layer (layer 0), I named it "black". When the level is ended we call fadeout() function like this:

function endLevel()
{
.
.
fadeout(0.5,"nextLevelName");
}

And when the next level is loaded we call fadeIn() function:

function tt::onLevelLoaded(%this, %scenegraph)
{
black.setVisible(true); //show the polygon because I hide it in the editor so I could see all the objects.
schedule(200,%this,"fadeIn",1);
}

//=================================
function fadeOut(%alpha,%level)
{
black.setFillAlpha(%alpha);
%alpha+=0.05;
if (%alpha<1.1) schedule(25,0,"fadeOut",%alpha,%level);
else
{
%level="game/data/levels/Level" @ %level @ ".t2d";
sceneWindow2D.loadLevel(%level);
}
}

//------------------------
function fadeIn(%alpha)
{
black.setFillAlpha(%alpha);
%alpha-=0.05;
if (%alpha>-0.1) schedule(25,0,"fadeIn",%alpha);
}

and that's it, you can now see your level fades out into black then loads the next level then fades in from black.

I hope this was helpfull.
#4
06/04/2011 (6:35 am)
@Amjad, Good idea. Thanks! ;)

I also tried another way.

function sceneFadeOut(%graph)
{
%objList = %graph.getSceneObjectList();
%count = %graph.getSceneObjectCount();
%obj = 0;

for(%i = 0; %i<%count; %i++)
{
%obj = getWord(%objList,%i);
%obj.fadeOut();
}
}

#5
06/04/2011 (6:40 am)
@yxm mac, that could work but why fade out lots of objects when you can fade out just one object, thus, the transition will go much smoother.
#6
06/04/2011 (6:55 am)
@Amjad Yahya, You are right. best way for needed!

Very helpful to me.

Thank you very much! ;)