Game Development Community

Binding mouse commands?

by James Ford · in Torque X 2D · 06/29/2007 (12:00 pm) · 3 replies

I know there are differences in TGB in the way commands are bound to keyboard keypresses and mouse key presses, so I'm guessing that is also the case in TX. It would be nice, however, if i could do something like:

int mouseId = InputManager.Instance.FindDevice("mouse0");
InputMap.BindCommand(mouseId, LeftButton??, null, OnPlayer1Start);

Is there a leftmousebutton objId defined somewhere? If not, what is the way to do this?
(also note i figured out Game.Instance.IsMouseVisible = true)

#1
06/29/2007 (12:15 pm)
Guess what worked, i should have known:
InputMap.BindCommand(mouseId, 0, null, OnPlayer1Start);

Actually mouse moust buttons are often refered to as button1,2,3 etc... if you offset that to start at 0 you can figure out how to bind all your mouse buttons.

Still though, it would be nice to know if there mousebuttons are defined as contants hidden somewhere in TX or XNA?
#2
06/29/2007 (12:21 pm)
Try: XMouseDevice.MouseObjects.LeftButton
#3
06/29/2007 (12:41 pm)
The reference material covers some of this in the "Input" tab of the Torque X Users Guide.

It's actually a pretty amazing system that's set up to handle input events. We use what at first glance appears to be a bit convoluted model of double-abstraction, but when you start working with it you'll realize that it is extremely powerful.

In a nutshell, Torque X has a InputManager class that allows you to create InputMaps, very similar to TGB/Torque, but also allows you to map inputs directly to an abstracted set of MoveMapTypes contained within a MoveManager...and each control object for each player can use the MoveManager to process inputs directly.

The long term benefit of the abstraction is that you can plan your game against the abstracted MoveMapTypes, and can also configure multiple device types to map to those MoveMapTypes--allowing you to code once for game play, and then "plug in" different input devices.

It may take a couple of read-throughs to get the gist of the system, but everyone would be well served to spend some time playing with the system to learn how to make best use of inputs.