Game Development Community

Changing Scene Data (Levels)

by Edward LaPlante · in Torque X 2D · 03/26/2008 (10:53 am) · 1 replies

I'm a newb in Torque, but a c# developer.

I'm having trouble unloading 1 scene and loading another. Both scenes work fine when loading from the "BeginRun" method. But I'm trying to start one scene (level) when something happens in the first.

I've tried both of the following:

protected override void BeginRun()
{
base.BeginRun();
SceneLoader.Load(@"data\levels\mainMenu.txscene");
this._state = GameState.MainMenu;
}

//Method get run when you click a button on the "mainMenu" scene.
public void StartGame()
{
SceneLoader.Unload(@"data\levels\mainMenu.txscene");
//I've also tried the following
SceneLoader.UnloadLast();
SceneLoader.Load(@"data\levels\level1.txscene");
}

I've also tried assigning a variable to the Scene Data and using the methods to unload and load a new scene.

Each time I run the game my screen goes black. I've also tried to not unload and I get the second scene overlayed on top of the first.

#1
03/30/2008 (5:04 pm)
Hi Edward,

This problem drove me CRAZY for days!

The solution is to create a new sceneview for your new level. The reason this isn't obvious is because the first time you load a level there's an automatically generated sceneview that gets used. But that sceneview is lost when you unload the level.

I've been meaning to publish a demo project for this. I'll try to have it up in the next day or two.