Game Development Community

TorqueX Input system

by Paul Bellezza · in Torque X 2D · 10/17/2007 (12:36 pm) · 6 replies

Are there any good tutorials or documentation or code examples for the TorqueX input system? I've managed to add a new action on a key press, however I want my action to remain active as long as the key is held and it seems that the way I have it, processTick only fires the action on a key press ignoring the key when it is held.

#1
10/17/2007 (7:28 pm)
Okay so now I've got it where the pressing a key acts like a toggle for the power. I'd still prefer a press and release solution if possible though...
#2
10/17/2007 (8:34 pm)
I think this should be possible. Try this... Let's say that the Z is the button that you want to map to. When you press the button an action starts and when you release the button, the action stops. The code should look like this:

private void _SetupInputMap(TorqueObject player, int playerIndex, String gamePad, String keyboard)
{
     // Set player as the controllable object
     PlayerManager.Instance.GetPlayer(playerIndex).ControlObject = player;
 
     // Get input map for this player and configure it
     InputMap inputMap = PlayerManager.Instance.GetPlayer(playerIndex).InputMap;
 
     int keyboardId = InputManager.Instance.FindDevice(keyboard);
     if (keyboardId >= 0)
     {
          [b]inputMap.BindAction(keyboardId, (int)Keys.Z, _HandleKeypressEvent);[/b]
     }
}

and then add your keypress event handler...

public void _HandleKeypressEvent(float val)
{
    if (val == 1.0F)
    {
        //Key has been pressed... call a start function
    }
    else if (val == 0.0F)
    {
        //Key has been released... call a stop function
    }
}

The secret is to use the BindAction() method which will give you any "change in state" of the button, in this case the change to press and then the change to release. Anyway, good luck.

John K.
#3
10/17/2007 (9:38 pm)
Thanks, I'll give that a whirl. I was using BindMove and not BindAction.
#4
10/17/2007 (9:49 pm)
Hmm, I did:

inputMap.BindAction(keyboardId, (int)Microsoft.Xna.Framework.Input.Keys.A, _recordButtonPressed);

In the SetupInputMap function and then I have:

protected virtual void _recordButtonPressed(bool value){
foreach (DragonActorComponent dragonActor in Movers)
dragonActor.Record(value);
}

As the handler, but I get an error for trying to overload BindAction, apparently BindAction takes two ints and a 'GarageGames.Torque.Sim.InputMap.ActionDelegate'

I'm guessing I need to change the handler function?
#5
10/17/2007 (10:36 pm)
Exactly, since the BindAction() method takes a delegate as a parameter, it can only call a method that matches the ActionDelegate signature. Try changing the bool parameter to a float parameter.

protected virtual void _recordButtonPressed(float value)
{
     foreach (DragonActorComponent dragonActor in Movers)
          dragonActor.Record(value);
}
#6
10/18/2007 (1:32 am)
I think I've got it working now, thanks. I need to finish writing the actual action so that I can test it fully but my debugging leads me to believe it works now.