Game Development Community

1.1 Beta: how to load/ unload levels?

by Alex Rice · in Torque Game Builder · 02/05/2006 (8:39 am) · 2 replies

None of the example games actually have more than 1 level, or data/levels/levelxxxx.cs script, and so don't actually need to load and unload levels.

The new level editor in 1.1 beta allows creation of a torquescript file with a scenegraph and it's sub-objects.
The loading and unloading , and management of level's assets is kind of unclear though. I assume we are supposed to use t2dSceneWindow::loadLevel() in gamescripts/initializeT2D.cs and also copy whatever functions we need from levelEditor/scripts/levelManagement.cs such as

function endLevel()
{
   if (isObject(levelEditorSceneWindow.scenegraph))
      levelEditorSceneWindow.scenegraph.delete();
      
   $currentLevelFile = %filename;
}

Is simply deleting the scenegraph doing to really do the job? Are all the resources going to get de-allocated?

If you look at this tutorial on TDN
http://tdn.garagegames.com/wiki/Torque_2D/GenreTutorials/PlatformerLevels
it suggests using a more complex method of Groups and Packages to manage levels. Why is the level management in 1.1 Beta so simplistic compared to this, does it matter? or is this something that is going to be added onto and clarified in future releases?

thanks in advance

Alex

#1
02/06/2006 (4:50 pm)
Deleting the scenegraph will, in fact, clean up all the objects it contains. t2dScenegraph::onRemove calls clearScene(true) which deletes all the objects in the scene.

Future iterations of the level builder will have much more robust handling of loading and unloading levels, but for now, just calling scenewindow.loadLevel(%levelFile) and scenewindow.scenegraph.delete() should work just fine.
#2
02/06/2006 (9:16 pm)
Thanks for confirming Adam. Glad to hear that technique is going to work fine. Great job on the Level Builder - if you are one of the developers.