Game Development Community

Can't load scenes dynamically

by Tony Pitman · in Torque X 2D · 06/08/2009 (7:14 am) · 9 replies

I have a TorqueX 2D game created from the starter game. I have created more than one level scene. I am calling

SceneLoader.Load(@"datalevelslevelData.txscene"); to load the first main scene.

On certain user input I want to change to a different scene. I call the following:

SceneLoader.Load(@"datalevelslevelMenu.txscene");

All of the scene objects don't show up and nothing works.

I tried adding a call to :

SceneLoader.UnloadLastScene(); before loading the new scene and when I do that I just end up with a black screen.

If I change the first call to load the second scene it works fine. In fact I have 3 scenes so far and I can load any one of them as the first one and it works fine. It is just when I try to change to a different scene that nothing works.

What do I do?

#1
06/08/2009 (11:12 am)
I think this thread is still accurate as the code I posted in there seems to work for me:
Main Post - Pretty much the same thing being asked here.
My Code - I made a function based off of some of the above discussion that allows you to just pass the string name of the level you want to load.

Brian
#2
06/08/2009 (11:32 am)
Your code works great! Thanks.
#3
06/08/2009 (12:38 pm)
No problem. I started a community links section on TDN in the Tutorials/Reference section that has that among other links that are interesting or helpful.

Brian
#4
06/08/2009 (12:44 pm)
Good idea. I can image with all the new XNA users this will become important.

I would love to see a tutorial that does something with a start screen / menu and then transition to game play. I have implemented this myself for my game, but others may not know where to begin...
#5
06/08/2009 (2:19 pm)
Yeah, I pretty much have a snapshot rotator component for splash screens, then a start screen "scene" that just takes input from the start button right now. No need for complex GUIs yet for me. ;)

Brian
#6
06/08/2009 (6:59 pm)
I have a related problem now. This has to do with InputMap. I am using the typical code like this:

PlayerManager.Instance.GetPlayer(playerIndex).ControlObject = player;

// Get input map for this player and configure it
InputMap inputMap = PlayerManager.Instance.GetPlayer(playerIndex).InputMap;

int gamepadId = InputManager.Instance.FindDevice(gamePad);
if (gamepadId >= 0) {
inputMap.BindAction(gamepadId, (int)XGamePadDevice.GamePadObjects.A, _OnAButton);
inputMap.BindAction(gamepadId, (int)XGamePadDevice.GamePadObjects.B, _OnBButton);
inputMap.BindAction(gamepadId, (int)XGamePadDevice.GamePadObjects.Up, _OnUpButton);
inputMap.BindAction(gamepadId, (int)XGamePadDevice.GamePadObjects.Down, _OnDownButton);
inputMap.BindAction(gamepadId, (int)XGamePadDevice.GamePadObjects.Left, _OnLeftButton);
inputMap.BindAction(gamepadId, (int)XGamePadDevice.GamePadObjects.Right, _OnRightButton);
}

// keyboard controls
int keyboardId = InputManager.Instance.FindDevice(keyboard);
if (keyboardId >= 0) {
inputMap.BindAction(keyboardId, (int)Keys.Enter, _OnAButton);
inputMap.BindAction(keyboardId, (int)Keys.Escape, _OnBButton);
inputMap.BindAction(keyboardId, (int)Keys.Up, _OnUpButton);
inputMap.BindAction(keyboardId, (int)Keys.Down, _OnDownButton);
inputMap.BindAction(keyboardId, (int)Keys.Left, _OnLeftButton);
inputMap.BindAction(keyboardId, (int)Keys.Right, _OnRightButton);
}

The problem I am having is when I switch scenes. Each scene has a different object that needs to get the input. It works at first, but as I go in and out of the menus the input starts to not work right.

Is there some kind of reset I need to call each time I switch to a new object getting the input?
#7
06/08/2009 (9:24 pm)
Hmm. I had a bunch of trouble with InputMaps recently. Turned out that calling PlayerManager.Instance.GetPlayer(playerIndex).ControlObject = player; twice on the same object completely screwed up the MoveManager. It wouldn't return any Move events in the ProcessTick() method. You might want to make sure you aren't doing that accidentally.
#8
06/08/2009 (9:27 pm)
Hmm, this is probably related, but I am not sure what to do about it. I say that because the main problem I have is when I go from playing to the menu and then back to playing. Obviously I need to set the controlobject to my main player object, then to my menu, then back to my main player object so I will be setting the controlobject to the same object twice. In between setting it to the same object, however, I will be setting it to another object. Is that ok? Do I have to make sure the null out the current one or something?
#9
06/09/2009 (9:27 am)
I hope you don't mind if I add a new tread with a different title just for this input problem now that the scene loading problem seems to be fixed...