Moving Between Scenes
by Jason Darby · in Torque Game Builder · 07/30/2009 (3:38 pm) · 2 replies
Have been trying to figure out a very simple question, which I am surprised isnt (as far as i can find), in the basic tutorials, and this is how to move between various scenes (levels or frames - depending on how you want to call it :)
All i want to do for the moment is make the scene change after 2 seconds. I found in the reference information about Schedule but couldnt get it to work. Ive also found that i can make it just to a particular single scene if i need to by calling :
sceneWindow2D.loadLevel(expandFilename("~/data/levels/itgLogo.t2d"));
So I guess I am asking how to move to a specific scene after two seconds. I also am wondering if I should be doing this code in the main game.cs file or creating a separate cs file that is called. I understand the benefits of doing this for object based function calls, but still trying to get my head around how it all fits together. (Guess there is no book available for 2D TGB?)
Jason
Ps Sorry for the simple questions, did search but the replies were not what I was expecting, and I am having some issues with the documentation not being clear (but thats just me being a muppet i suppose :)
About the author
Computer games book author, have written 6 game creation books, published by Cengage Course Technology. Owner of Arcade website www.madword.com and Castle software.
#2
Also, the full prototype here changes levels in the most straightforward TGB way ever - just open up the code and find the startgame call.
07/30/2009 (4:22 pm)
Just for bulletproofing the great above suggestion for future uses with the same question, the BehaviorShooter uses a behavior that loads a new level upon the death of an object. See TakesDamageAdv on the mothership at the end of the level. I think it's also used on the player to reset upon death.Also, the full prototype here changes levels in the most straightforward TGB way ever - just open up the code and find the startgame call.
Torque Owner Ehrlich
function loadNewLevel(%levelFile, %delay) { // Prevents a crash ;) if (%delay $= "") %delay = 100; // If you haven't included a directory then we'll use the default if (!isFile(%levelFile)) %levelFile = "game/data/levels/demo/" @ %levelFile; // Add on the extension if needed %fileExtn = ".t2d"; if (getSubStr(%levelFile, strlen(%levelFile) - strlen(%fileExtn), strlen(%fileExtn)) !$= %fileExtn) %levelFile = %levelFile @ %fileExtn; // Load the file if possible $gameRunning=true; $levelName=%levelFile; if (isFile(%levelFile)) schedule(%delay, 0, "startGame", %levelFile, %empty); else warn("Level not found: " @ %levelFile); }i found this function long ago in the TDN, and its rpetty usefull... i made some mods to my likes, but basically, thats it.
to use it, just call it this way
now, if you dont wanna use that method, then you can use this one
it should work.