Game Development Community

How do I load a new level scene using Torque X and Platformer Kit

by Darrell · in Torque X 2D · 01/22/2010 (11:08 pm) · 3 replies

Im having a issue loading a new scene.. In torque i have a "egg" with the GoldenEggCollectibleComponent added to it.. and im using the below code in my game.cs


public void LevelCompleted()
{
SceneLoader.Unload(@"datalevelslevel_01.txscene");
SceneLoader.Load(@"datalevelslevel_02.txscene");

}


When I play it in torque.. when i collide with the egg.. torque crashes ;.. I get this error


" Cannot access a disposed object.
Object name: 'Texture2D'"


Please help. Im trying to learn my way thru this.. Thanks If you are able to please provide as much detail as possible. Thanks

#1
01/23/2010 (3:26 am)
I prefer to use UnloadLastscene This still may crash as there will possibly be a time with no scene, I would go to a UI screen or something in between,

public void LevelCompleted()
{
   Game.Instance.SceneLoader.UnloadLastScene();
   Game.Instance.SceneLoader.Load(@"datalevelslevel_02.txscene");
}

or even try this:

public void LevelCompleted()
{
   Game.Instance.SceneLoader.Load(@"datalevelslevel_02.txscene");
   Game.Instance.SceneLoader.Unload(@"datalevelslevel_01.txscene");
}

Load the new scene before unloading the old one. so you are always in a scene.

#2
01/23/2010 (3:53 am)
Thanks for the advice.. Tried both.. same error came back..


" Cannot access a disposed object.
Object name: 'Texture2D'"
#3
01/23/2010 (11:24 am)
Right, you are in a scene, that is trying to run or something is spawned after or during the call to unload. I had an object that I had spawned another object in the _OnUnregister call. When the scene was unloaded the unregister was called and there was no scene...

I would definitely do some sort of loading interstitial screen between scenes anyway, I don't know how or if you have any gui screens but basically it would be like this:

GuiLoadScreen loadScreen = new GuiLoadScreen();
GUICanvas.Instance.SetContentControl(loadScreen);

and in the GuiLoadScreen constructor you would put the unloadLastScene() followed by the load(newscene)

I know I have seen this spelled out more completely in this forum.