Game Development Community

Dissolving scene change.

by Cosmic Logic · in Torque X 2D · 05/18/2010 (7:09 pm) · 15 replies

I'm wondering if anyone has tried making a dissolving scene change.

Loading a new scene and then having the current one dissolve out or the new one dissolving in.

If it hasn't been done could anyone give me an idea where I would start with this?

I had a jimmy rigged idea of just taking a screen shot of all of my scenes once they're done and using that as an imitiation effect. Load up that image, dissolve it over top of everything, load the new scene underneath and then get rid of the overlayed image. All of my scenes are just the size of my camera, maybe two or three times the size but that's it. Loading time shouldn't be an issue.

I could just do a fade in and out with a splash gui if all else fails though.

#1
05/19/2010 (6:04 am)
Yes, I do this sort of thing - cross fading scenes, and stuff like that. The way I do it is to have the scenes in separate sceneviews. Do your transition (such as fading in one scene while fading out the other) and then unload the old scene and remove it's sceneview.

If none of that makes much sense though, then you might find your jimmy rigged solution is the best approach - it's certainly simple enough and in theory should work perfectly well for fading in over the existing scene. The trade off would be time spent taking snapshots and the extra disk space the images would take up - but it sounds like that won't be an issue in this instance.
#2
05/19/2010 (10:18 am)
Did you manage to actually cross fade the scenes or did it just fade to black?

If you did crossfade, how did you do it? Just set some opacity values? (Still pretty new to TX and C# but getting there)
#3
05/19/2010 (11:06 am)
couldn't you just save your final image to a different render target, render that to a texture and set that texture as your guicontrol, and fade it out by scaling its opacity?
#4
05/19/2010 (12:16 pm)
@Michael: yes you could.

@Cosmic: yes I actually cross fade them and it is done by setting VisibilityLevel on the objects.


(one advantage of the multiple sceneviews approach is that it will cross fade scenes that have moving or animated objects in them)
#5
05/19/2010 (5:03 pm)
Thanks :D

I've never really played with sceneviews a whole lot. I'm going to make a test project and play around a bit and see what I can come up with.
#6
05/20/2010 (6:15 pm)
@Duncan, that sounds interesting, but if you are setting visibility level on the objects themselves, having multiple objects layered in a scene would be haphazard wouldn't it? ... you'd have to set visibility on the entire view, right?
#7
05/21/2010 (7:04 am)
Quote:having multiple objects layered in a scene would be haphazard

How do mean?
#8
05/21/2010 (7:31 am)
I think I see what you might mean: objects in the same scene would show through each other rather than 'fading the scene as one image'. A good point.

I don't currently have this issue, but the solution would be to put a postprocessing effect on each view to modify the visibility of the views that way (since iirc you cannot set the visibility of the sceneview itself).
#9
05/22/2010 (2:44 pm)
@duncan thats what I meant... thanks for clearing things up.
#10
05/22/2010 (4:41 pm)
Hey,

I got this up and running. The fade that is.

Pretty much what I did was instead of using the SceneLoader.Load I just made a new T2DSceneData object, set a OnLoaded delegate that sets VisibilityLevel on every T2DSceneObject to 0 then used the .Load method on that T2DSceneData object: ie:

_sceneData = new TorqueSceneData();
         _sceneData.OnLoaded = delegate() {
            foreach(object obj in _sceneData.Objects) {
               T2DSceneObject txObj = null;
               try {
                  txObj = (T2DSceneObject)obj;
               } catch(InvalidCastException) {}
               if(txObj != null) {
                  txObj.VisibilityLevel = 0;
               }
            }
         };
         _sceneData.Load(scenePath);
         Game.Instance.SceneFadingRequested = true;

Mind you the .visibilitylevel property doesn't work unless you play with some things in the source code. Old bug, I can let you know what you need to change if you have it.

From there that Game.Instance.SceneFadingRequested = true just sets this going in my game's update method:

// Scene fading
         if(_sceneFadingRequested) {
            _timeCounter += gameTime.ElapsedGameTime.Milliseconds;
            if(_timeCounter > 5) {
               _timeCounter = 0;
               _sceneFadingRequested = _loader.fadeObjects();
            }
         }

the _loader is a class that I've made that deals with all of my scene and menu switching. It's also where I stored that _sceneData object.

This is the fadeObjects method:

public bool fadeObjects() {
         // track the level of visibility
         float i = 0;
         foreach(object obj in _sceneData.Objects) {
            // store the current object
            T2DSceneObject txObj = null;
            try {
               txObj = (T2DSceneObject)obj;
            } catch(InvalidCastException) { } // if it's not a t2dsceneObject this will just get skipped and txObj will be null
            if(txObj != null) {
               txObj.VisibilityLevel += 0.1f;
               i = txObj.VisibilityLevel;
            }
         }
         if(i >= 1) {
            return false;
         } else {
            return true;
         }
      }

What happens is every time update is called it fades in a little bit more. Once fadeObjects returns false (when the objects are fully faded ing) the update method resets my FadeRequest variable.

As far as I've got it worked so far I'm just loaded a temorary combat scene over top of the one going so I'm not unloading an old scene yet. You'll have to toss that in. I'm planning on having two T2DSceneData objects eventually. _newSceneData and _oldSceneData. Once the new one is loaded it will unload the old.

It's not exactly a cross fade, it just fades the new one in but it looks nice :) I've also set up the layers in my txscene files so that the combat scene's objects are higher up than my regular ones.

Hope this helps. If you need anything cleared up let me know.
#11
05/22/2010 (7:05 pm)
The TorqueX GUI 2D sample project in the latest version has an example of a "class GuiSplashScreen : GUISplash, IGUIScreen"

#12
05/23/2010 (7:55 am)
@Cosmic: you don't need to catch the InvalidCastException. Just do:

txObj = obj as T2DSceneObject;

...and test that txObj != null
#13
05/23/2010 (3:09 pm)
Awesome. Thanks.

That way I don't get a flood of "A first chance exception of type whatever..." in the console either.

Is this something along the same lines you have Duncan?
#14
05/24/2010 (6:51 am)
For casting to different types? yes I usually do it like that.
#15
08/21/2011 (7:22 pm)
How about fading in a black overlay layer and then unloading the first scene. Then loading the second scene under the overlay and then fading out the black overlay?