Game Development Community

How to use the mouse in a TGBX game?

by Laurence Grant · in Torque X 2D · 01/08/2007 (2:06 pm) · 2 replies

Is there a sample like this anywhere, but for the mouse?


// Taken directly from the Space Shooter Demo

int gamepadId = InputManager.Instance.FindDevice(gamePad);
if (gamepadId >= 0)
{
inputMap.BindMove(gamepadId, (int)XGamePadDevice.GamePadObjects.LeftThumbX, MoveMapTypes.StickAnalogHorizontal, 0);
inputMap.BindMove(gamepadId, (int)XGamePadDevice.GamePadObjects.LeftThumbY, MoveMapTypes.StickAnalogVertical, 0);
inputMap.BindMove(gamepadId, (int)XGamePadDevice.GamePadObjects.RightThumbX, MoveMapTypes.StickAnalogHorizontal, 1);
inputMap.BindMove(gamepadId, (int)XGamePadDevice.GamePadObjects.RightThumbY, MoveMapTypes.StickAnalogVertical, 1);
inputMap.BindMove(gamepadId, (int)XGamePadDevice.GamePadObjects.A, MoveMapTypes.Button, 0);
inputMap.BindMove(gamepadId, (int)XGamePadDevice.GamePadObjects.Left, MoveMapTypes.Button, 1);
inputMap.BindMove(gamepadId, (int)XGamePadDevice.GamePadObjects.Right, MoveMapTypes.Button, 2);
inputMap.BindMove(gamepadId, (int)XGamePadDevice.GamePadObjects.Up, MoveMapTypes.Button, 3);
inputMap.BindMove(gamepadId, (int)XGamePadDevice.GamePadObjects.Down, MoveMapTypes.Button, 4);
inputMap.BindMove(gamepadId, (int)XGamePadDevice.GamePadObjects.LeftTriggerButton, MoveMapTypes.Button, 0);
inputMap.BindMove(gamepadId, (int)XGamePadDevice.GamePadObjects.RightTriggerButton, MoveMapTypes.Button, 0);
inputMap.BindMove(gamepadId, (int)XGamePadDevice.GamePadObjects.Start, MoveMapTypes.Button, 5);

inputMap.BindAction(gamepadId, (int)XGamePadDevice.GamePadObjects.B, _OnBButton);
inputMap.BindAction(gamepadId, (int)XGamePadDevice.GamePadObjects.Back, _OnBackButton);
}

#1
01/08/2007 (4:43 pm)
I don't think we have any current samples which use the mouse (we've used the mouse in some old samples but we didn't include any of those in the sdk). But using the mouse is much like using other devices. You first need to find the mouse id

int mouseId = InputManager.Instance.FindDevice("mouse");

Then you need to decide what mouse "objects" you want to bind to. See XmouseDevice.MouseObjects for the enum which lists what can be bound. You use this just as you use XGamePadDevice.GamePadObjects in the above sample.

Note that mouse has a different input range than other devices (i.e., screen coords) which means it will act a little different.
#2
01/08/2007 (8:06 pm)
I understand now. I didn't realize that gamePad and keyboard were being passed into the setup function and were infact strings. My bad for not spedning more time on it. Thanks Clark