Game Development Community

Objects not appearing after I re init game

by Garrett Brown · in Torque Game Builder · 02/25/2006 (12:09 pm) · 3 replies

Hello all,

I've implmented a way in my game for the user to exit out of the game and go back to the main menu. The problem is this:
The first time the game starts, everything is fine, but if the user exits in the middle of the game and goes back to the main menu to re start the game, none of the objects are there on screen. The debug info tells me that objects are there, but you can't see any of them, and the game isn't "playing"- as in the game isn't playing invisibly, as I would hear sound effects if it were so. Here are some snippets of code that might help see the problem:

This is my startgame function, it gets called by pressing the start button on my mainmenu.gui
function startGame()
{
       if ($gameStarted)
	return;
       $gameStarted = true;
       alxStop($IntroMusic);
       $levelOneMusic = alxPlay(LevelOneMusic);
       Canvas.setContent(mainscreengui);
       // Create our scenegraph
       new t2dSceneGraph(t2dScene);
       // Associate Scenegraph with Window.
       sceneWindow2D.setSceneGraph( t2dScene );
	   
       t2dScene.setDebugOn(0,0);
       //t2dScene.setDebugOn(0,1);
       t2dScene.setDebugOn(0,5);
       t2dScene.setScenePhysicsFPSActive(1);
       t2dScene.setScenePhysicsTargetFPS(125);
       
       loadImages();
       SetupPipes();
       ResetStaticLine();
       spawnBall();
       CreateBallGrindEffect();
       // Set the current camera position
       sceneWindow2D.setCurrentCameraPosition("0 0 100 75");
      
}
This is the endgame function that gets called by pressing the quit button on the inGameGui.gui
it boots the player back to the menu screen
function endGame()
{
	alxStop($levelOneMusic);
	$gameStarted = false;
	if (isObject(t2dScene))
	{
		t2dScene.clearScene(true);
		t2dScene.delete();
	}
	canvas.popDialog(InGameGUI);
	cancel($ballSpawner);
	LoadIntroGUI();

}
This is the loadIntroGUI, just in case
function LoadIntroGUI()
{
	canvas.setContent(MainMenu);
	$introMusic = alxPlay(IntroMusic);
}

I feel like it's something to do with the SceneWindow not getting shown, or not being in the right place, but I haven't been able to find anything similar to this. I'm also not sure if I'm using setContent correctly to put gui's up, and if there is a way to pop gui's off. I've tried function calls like MainMenu.pop(), but the console tells me thats not valid.
Any help would be greatly appreciated!

Thanks,
G

About the author

I work at n-Space, located in Orlando, FL as a designer. When I'm not there, I work on side projects, generally using TGB. Side projects I've finished are Oddictive, Klockotock, and AstroDriller3020


#1
02/25/2006 (12:37 pm)
At first glance I'd probably say it is because you re-create the sceneGraph (and associate the new one with the sceneWindow) each time you start the game. Try only creating and setting that if one doesn't already exist, testing isObject(t2dSceneGraph) perhaps.
#2
02/25/2006 (1:17 pm)
Thanks for the quick response. I tried doing this, changing my code so that it looks like this:
function startGame()
{
	if ($gameStarted)
		return;
	 $gameStarted = true;
	alxStop($IntroMusic);
	$levelOneMusic = alxPlay(LevelOneMusic);
	Canvas.setContent(mainscreengui);
	// Create our scenegraph
	if (!isObject(t2dScene))
	{
		echo("t2dScene is not and Object!");
		new t2dSceneGraph(t2dScene);
		// Associate Scenegraph with Window.
		sceneWindow2D.setSceneGraph( t2dScene );
	}
                // etc...

but it didn't change anything. I thought that when I called t2dScene.delete() in function endGame(), that it would delete the scenegraph and be ok to new in startGame. I'm leavin the safe check in though and thank you for your input. Just out of experimentation, i commented out the deletion and clearing in my endGame() function to look like this:
if (isObject(t2dScene))
{
	//t2dScene.clearScene(true);
	//t2dScene.delete();
		
}
so I could see what it would do with the isObject checks in startGame(). Doing this, I had objects on the screen, but it was just the last state that the scene was in before I exited, as in, there was no movement or interaction. Like a snapshot. I've got no clue what's goin on, but it's problem something goofy that I'm doin wrong. :(

G
#3
02/25/2006 (1:25 pm)
Wow, I am an idiot...I was setting setScenePause(true) while the inGameGui was running, and never setting it back to false...problem fixed! That's about an hour of my life I'll never get back now. Doh!

G