Game Development Community

Sceneloader - Load and Unloading issues

by NighTerrorX · in Torque X 2D · 06/11/2008 (4:40 am) · 7 replies

Hey guys and gals, I am having an issue with the loading and unloading of scenes. I am trying to simply unload a stage, then load the next based on a triggered event. I am using Torque X 2.0.

I have my level complete logic inside of Game.cs, and it is triggered inside a component I made which simply has a collision and when triggered it calls the level complete logic through: Game.Instance.LevelComplete();

Inside my LevelComplete I have
Game.Instance.SceneLoader.Unload(@"data\levels\level1.txscene"); //unload last level
Game.Instance.SceneLoader.Load(@"data\levels\level2.txscene"); //load next level

The issue is that it doesn't unload level1 -- but it does load level 2. So I am left with 2 scenes loaded.

I have seen this thread which says to load a blank scene:
http://www.garagegames.com/mg/forums/result.thread.php?qt=73882

But that doesn't work for me either -- I am getting a crashing bug when I follow it.

Is the Unload method the proper way to unload a level?

There has to be a simple way to transition to a new level. Can someone please point me in the right direction...I am sure I am missing something here...but I am just not sure what.

#1
06/11/2008 (6:31 am)
I wrote a utilitie to delete all objects. Just remember to also delete the scene graph. Because once you load your second scene you'll have two scene graphs with the same name.
#2
06/11/2008 (8:50 am)
Does that mean that the Unload method is useless?

Will: In your utility, where do you delete the items? Is there a pre-built Container that has all the loaded items in a scene by default. I am sorry I am not 100% up to speed on my Torque X/XNA yet.
#3
06/11/2008 (9:22 am)
Yes.. I use the scene graph itself. Take a look at the microbes tutorial, it explains my method pretty well on how to get all the objects in a scene. You have to actually get the SceneGraph though... I might as well just post my whole method..

I think its a good practice to allways rename and keep track of your scene graphs, so I named mine "CurrentSceneGraph"

the default name is "DefaultSceneGraph"

The first bit of code is fired


//this is inside a component
DatabaseUtil.deleteAll();
            T2DSceneGraph _sceneGraph = (T2DSceneGraph)TorqueObjectDatabase.Instance.FindObject("CurrentSceneGraph");
            _sceneGraph.MarkForDelete = true;
            Game.Instance.SceneLoader.Load(@"data\levels\NewLevel.txscene");
            T2DSceneGraph _sceneGraphNew = (T2DSceneGraph)TorqueObjectDatabase.Instance.FindObject("DefaultSceneGraph");
            _sceneGraphNew.Name = "CurrentSceneGraph";


//this is the DatabaseUtil
 public static void deleteAll()
        {
            List<ISceneContainerObject> _allObjects = new List<ISceneContainerObject>();
            T2DSceneGraph _sceneGraph = (T2DSceneGraph)TorqueObjectDatabase.Instance.FindObject<T2DSceneGraph>("CurrentSceneGraph");
            Vector2 _vector = new Vector2();
            _sceneGraph.FindObjects(_vector, 9999, TorqueObjectType.AllObjects, (uint)0xFFFFFFFF, _allObjects);
            foreach (T2DSceneObject _obj in _allObjects)
            {
                if (_obj is T2DSceneObject)
                {
                    _obj.MarkForDelete = true;
                }
            }
        }
#4
06/11/2008 (6:09 pm)
Thank you...all the information you provided put me on the right track.
#5
06/18/2008 (7:37 am)
_sceneGraph.FindObjects(_vector, 9999, TorqueObjectType.AllObjects, (uint)0xFFFFFFFF, _allObjects);

What would be the syntax if I wanted to find only "enemy"-objects instead of all objects?
#6
06/20/2008 (2:17 pm)
List<T2DSceneObject> _objectList = new List<T2DSceneObject>();
_objectList = TorqueObjectDatabase.Instance.FindObjects<T2DSceneObject>();

I'm actually using that code to get lists of objects. At that point you can check the name or if the object has an enemy component on it, and mark it for delete.. using a foreach loop

foreach (T2DSceneObject _obj in _objectList)
            {
                if (_obj.Name == "Enemy")
                {
                    _obj.MarkForDelete = true;
                }
            }
#7
06/21/2008 (12:49 pm)
That's it!
Thank you very much, Will :-)