Inputmap keyboard buttons stop working on new sceneload
by Raymond Ku · in Torque X 2D · 03/03/2010 (4:13 am) · 2 replies
This is the current situation
I created a playter template in the first level1.txscene
i spawn the player the same way as in the blaster tutorial.
The player walks right until he walks to a certain area and triggers Game.Instance.LevelCompleted()
When the second level loads, the player continues walking right and the keyboard arrow buttons do not work.
All other keyboard inputmaps function correctly
The only difference i can tell is that the arrow keys use BindMove
whereas the other commands use BindCommand
Do i need to reregister the inputmap or delete the old one or something when i spawnplayer the second time?
code for my playermovement
I created a playter template in the first level1.txscene
i spawn the player the same way as in the blaster tutorial.
The player walks right until he walks to a certain area and triggers Game.Instance.LevelCompleted()
When the second level loads, the player continues walking right and the keyboard arrow buttons do not work.
All other keyboard inputmaps function correctly
The only difference i can tell is that the arrow keys use BindMove
whereas the other commands use BindCommand
Do i need to reregister the inputmap or delete the old one or something when i spawnplayer the second time?
public void LevelCompleted()
{
SceneLoader.UnloadLastScene();
SceneLoader.Load(@"data\levels\levelData2.txscene");
//create a renderable canvas for the scene
GUIStyle stylePlayGui = new GUIStyle();
GUISceneview playGui = new GUISceneview();
playGui.Style = stylePlayGui;
SpawnPlayer();
//switch over to the new canvas
GUICanvas.Instance.SetContentControl(playGui);
}code for my playermovement
PlayerManager.Instance.GetPlayer(0).ControlObject = SceneObject;
InputMap inputMap = PlayerManager.Instance.GetPlayer(0).InputMap;
int keyboardId = InputManager.Instance.FindDevice("keyboard");
if (keyboardId >= 0)
{
inputMap.BindMove(keyboardId, (int)Keys.Left, MoveMapTypes.StickDigitalRight, 0);
inputMap.BindMove(keyboardId, (int)Keys.Right, MoveMapTypes.StickDigitalLeft, 0);
inputMap.BindMove(keyboardId, (int)Keys.Up, MoveMapTypes.StickDigitalUp, 0);
inputMap.BindMove(keyboardId, (int)Keys.Down, MoveMapTypes.StickDigitalDown, 0);
}About the author
http://cip-game.blogspot.com
#2
www.torquepowered.com/community/forums/viewthread/94779
03/03/2010 (6:40 pm)
Solved found my answer in this threadwww.torquepowered.com/community/forums/viewthread/94779
Torque Owner Raymond Ku
no studio
I have my player template from the first scene persistent checkbox turned off. I just copy pasted the template and renamed scripting to "PlayerTemplate" again.
I'm not sure if i'm understanding this correctly, but it seems when i unload a scene, all the templates i created are deleted too. is this correct?
After a few more tests it seems when i trigger the unload scene and reload scene, the arrow keys that i was last pressing will remain pressed for the second level.
Example: if i was pressing right and up at the same time as i enter into the zone which triggers level completed function, then when the second level loads the player will travel right and up continuously.
Any help would be appreciated. Thanks