Lose Control of Player after Pop/Push [SOLVED]
by Aaron Scovel · in Torque X 2D · 09/27/2010 (5:23 pm) · 6 replies
Hi Guys!
I'm having a bit of an issue when using push and pop with the movement component. I believe things are working for the most part. My problem is moving the player after it has been popped/pushed...
Here is my code in the ProcessTick:
The above code Pushes the map "inputMap" when switching from the pause screen. All the mapped controls are setup and I can use the controls to pause, exit, etc... However I cant move my player anymore! AHH!
It appears "move" in the processTick remains null
I can call _OnRegister(_sceneObject); and then it works, but do I really need to re register when it should already be registered?
Many thanks for any help.
I'm having a bit of an issue when using push and pop with the movement component. I believe things are working for the most part. My problem is moving the player after it has been popped/pushed...
Here is my code in the ProcessTick:
if (Game.Instance.Engine.GameTimeScale == 1 && _isPaused)
{
InputManager.Instance.PushInputMap(inputMap);
_isPaused = false;
}The above code Pushes the map "inputMap" when switching from the pause screen. All the mapped controls are setup and I can use the controls to pause, exit, etc... However I cant move my player anymore! AHH!
It appears "move" in the processTick remains null
I can call _OnRegister(_sceneObject); and then it works, but do I really need to re register when it should already be registered?
Many thanks for any help.
About the author
Previously a PHP/MySQL Programmer/Web Developer of 10 years. In Aug 2010 I decided to change careers, and this is were I landed! I also parent 3 kids full time. TopNotched.com
#2
Thanks for the code though!, I will definitely try this out on my other projects, looks like a great way to do that.
I guess for now I will use _OnRegister(_sceneObject); to gain player control again, just seems redundant in code when the map has already been created.
09/27/2010 (10:21 pm)
@Cosmic: I must use 2 input maps in this project. Basically the 2nd input map is part of a pause menu component that is automatically initiated when active. The component is going to be an "add-on" I'll be providing to the community, so I want to minimize the required end user coding.Thanks for the code though!, I will definitely try this out on my other projects, looks like a great way to do that.
I guess for now I will use _OnRegister(_sceneObject); to gain player control again, just seems redundant in code when the map has already been created.
#3
But this method would still require you to push your input map back onto the stack. I actually prefer that anyways (don't actually call onRegister, just call the function that pushes an input map onto the stack), (do clear the old inputs so they don't stack up, or pop one off, or whatever)
Anyways, if you begin to treat the input manager like a regular list that you have to maintain and pay attention to, you'll start getting better results. Try to ignore it, and your game will fail in transitions.
09/28/2010 (4:31 pm)
One thing I found I had to do was write my own codes to clear input maps, and clear input managers, when I don't want input maps overlapping. But this method would still require you to push your input map back onto the stack. I actually prefer that anyways (don't actually call onRegister, just call the function that pushes an input map onto the stack), (do clear the old inputs so they don't stack up, or pop one off, or whatever)
Anyways, if you begin to treat the input manager like a regular list that you have to maintain and pay attention to, you'll start getting better results. Try to ignore it, and your game will fail in transitions.
#4
move (example: move.Sticks[0].X * 20.0f;) remains null.
Flow of Events
Original Screen
Original InputMap (inputMap)
InputManager.Instance.PushInputMap(inputMap);
InputManager.Instance.PopInputMap(inputMap);
New Screen
New InputMap (VGUIinputMap)
InputManager.Instance.PushInputMap(VGUIinputMap);
InputManager.Instance.PopInputMap(VGUIinputMap);
Original Screen
InputManager.Instance.PushInputMap(inputMap);
I have also tried ClearInputMapStack() (clears the whole stack - found in CEV)
I can give WASD,up,down,left,right different commands and they work, they just refuse to "move" the player. If I call _onRegister() the brains come back.
09/28/2010 (5:16 pm)
@Will: The new & old maps are working just fine. Its just the "move" that no longer works, the old map becomes a vegetable (lost its brains but still has its body). There is no overlapping and all input is working, except player control (WASD,up,down,left,right that outputs to "move").move (example: move.Sticks[0].X * 20.0f;) remains null.
Flow of Events
Original Screen
Original InputMap (inputMap)
InputManager.Instance.PushInputMap(inputMap);
InputManager.Instance.PopInputMap(inputMap);
New Screen
New InputMap (VGUIinputMap)
InputManager.Instance.PushInputMap(VGUIinputMap);
InputManager.Instance.PopInputMap(VGUIinputMap);
Original Screen
InputManager.Instance.PushInputMap(inputMap);
I have also tried ClearInputMapStack() (clears the whole stack - found in CEV)
I can give WASD,up,down,left,right different commands and they work, they just refuse to "move" the player. If I call _onRegister() the brains come back.
#5
My mistake, I thought you were only doing buttons, for buttons it doesn't matter, but for control sticks, they have to be assigned to a player because of the "move" thing.. its tricky.
-Will
edit:
here's the code I'm talking about
Just make sure you are assigning the correct index too.
09/28/2010 (6:53 pm)
When it's move remains null its because your player is not the object.. only one torqueObject can ever be your player, so check that instance, and push that to the stack...My mistake, I thought you were only doing buttons, for buttons it doesn't matter, but for control sticks, they have to be assigned to a player because of the "move" thing.. its tricky.
-Will
edit:
here's the code I'm talking about
PlayerManager.Instance.GetPlayer(playerIndex).ControlObject = player;
Just make sure you are assigning the correct index too.
#6
Appreciate you setting me straight!
Innocent bystanders: This will bring back the InputMap & set the correct control index/torque object correctly for "move" (using the default MovementComponent index/object code).
Thanks Will!!!!!
09/28/2010 (7:14 pm)
Duurrr... :-)Appreciate you setting me straight!
Innocent bystanders: This will bring back the InputMap & set the correct control index/torque object correctly for "move" (using the default MovementComponent index/object code).
InputManager.Instance.PushInputMap(inputMap); PlayerManager.Instance.GetPlayer(_playerNumber).ControlObject = _sceneObject;
Thanks Will!!!!!
Torque Owner Cosmic Logic
public enum GameStateTypes { Playing, Paused, Menu, EndGame}In my game class I have:
public GameStateTypes GameState { get; set; }Now all I need to do in my input map is put a switch in my button methods:
public void _onBButton(){ switch(Game.Instance.GameState){ case GameStateTypes.Playing: // fire something or whatever break; case GameStateTypes.Paused: // do something else break; } }And in my process tick I have an if that checks the game state type.
All of my ticking game objects reference this GameState, so I don't even have to bother with GameTimeScale. I simply change my Game.Instance.GameState to Paused and everything acts accordingly.
To me it seemed a way simpler way to go. Hope this helps.