Using Joystick
by James Jacoby · in Torque Game Builder · 01/06/2006 (11:24 pm) · 18 replies
This is probably a lame question, but I can't seem to find the answer in the documentation or on the forums.
Q: How do you turn on and use a joystick?
I tried this but got not response (works with keyboard):
moveMap.bind(joystick0, xaxis, "moveLeft");
moveMap.bind(joystick0, yaxis, "moveRight");
moveMap.bind(joystick0, button0, "jump");
I even tried adding thse lines which I saw in someone's post:
$enableDirectInput = 1;
activateDirectInput();
enableJoystick();
Any ideas? What am I missing?
Thanks!
Q: How do you turn on and use a joystick?
I tried this but got not response (works with keyboard):
moveMap.bind(joystick0, xaxis, "moveLeft");
moveMap.bind(joystick0, yaxis, "moveRight");
moveMap.bind(joystick0, button0, "jump");
I even tried adding thse lines which I saw in someone's post:
$enableDirectInput = 1;
activateDirectInput();
enableJoystick();
Any ideas? What am I missing?
Thanks!
About the author
#2
01/09/2006 (9:19 pm)
I downloaded your code and compiled example. It looks awasome... Good work. Am I correct that joysticks do not work with the stock T2D then? I'd love to incorperate your changes into my build, but I can't even get the new T2d 1.4 to compile, let alone merge with my stuff and this. Unlike past projects, I was hoping I could use T2D stock this time around. It's a pain to migrate all my changes from version to version :P
#3
01/10/2006 (7:51 am)
Stock T2D does support joysticks. My additional functionality adds support for gamepads, POV hats, D-pads (same thing), and rumble. You should be able to run the same Joystick code as in my samples against stock T2D and everything will work except for the rumble.
#4
DirectInput joystick failed to enable!
My gamepad works fine when I run your exe / example scripts. However, when I try to use the stock T2D 1.1 Alpha 2 exe it fails to enable.
I'm stumped.
01/10/2006 (4:15 pm)
I tried to run the code from your examples, but I get an error in the console after executing the command "enableJoystick();"DirectInput joystick failed to enable!
My gamepad works fine when I run your exe / example scripts. However, when I try to use the stock T2D 1.1 Alpha 2 exe it fails to enable.
I'm stumped.
#5
01/10/2006 (8:27 pm)
Interesting. Do you have the DirectX SDK installed, by any chance? Does their "Joystick" sample work for you? I'm wondering if you are missing a joystick driver perhaps? Does your joystick work with other games?
#6
01/10/2006 (9:50 pm)
I don't have the SDK, but I may download it to test it out. The gamepad works fine with other games and the drivers are installed and working. I'll try it with the SDK and report back. Thanks for your help with this. Anything you want help with? I've gotten pretty deep into T2D.
#7
In client.cs, initClient() ...
$enableDirectInput = "1";
activateDirectInput();
enableJoystick(); // Throws an error: DirectInput joystick failed to enable!
InitBaseClient();
... includes ...
bindJoystickEvents(); // From your code
Canvas.setContent(mainScreenGui);
Canvas.setCursor(DefaultCursor);
setupT2DScene();
01/10/2006 (10:24 pm)
It works with the DirectX SDK... here is the exact code from my game:In client.cs, initClient() ...
$enableDirectInput = "1";
activateDirectInput();
enableJoystick(); // Throws an error: DirectInput joystick failed to enable!
InitBaseClient();
... includes ...
bindJoystickEvents(); // From your code
Canvas.setContent(mainScreenGui);
Canvas.setCursor(DefaultCursor);
setupT2DScene();
#8
01/10/2006 (11:18 pm)
Oh, right, sorry. I missed a key word in your earlier post. Gamepads are not supported in stock 1.1... just "pure" joysticks. My diff supports both gamepads and joysticks and Xbox 360 controllers.
#9
01/10/2006 (11:19 pm)
Incidentally, this is a "problem" with TGE, not T2D. I will be creating a version of my diff for 1.4 when we get a build of T2D on 1.4, but unfortunately, you will still need to build your own EXE to get this functionality. With VS2005 Express being a free download, I'd recommend you get a build environment going soon. :-)
#10
01/11/2006 (9:41 am)
I finally got it to compile on my old Visual Studio and made the needed changes. Unfortunatley, I had to make a few changes to the code and project to get it to compile (which is scary). I'll post the code snippet when I get home. Once I was able to trace through the code, it was obvious what the issue was. I only had to add a total of about 10 lines of code to get support for gamepads and POV hat's working. Why on Earth does Torque differentiate between "Joysticks" and "Gamepads" ?? Whatever. Thanks for your help on this one.
#11
01/11/2006 (4:32 pm)
No problem. Glad I could help.
#12
To get gamepads (and possibly others) working:
In winDirectInput.cc: enumerateDevices()
Find:
mDInputInterface->EnumDevices( DI8DEVTYPE_JOYSTICK, EnumDevicesProc, this, DIEDFL_ATTACHEDONLY );
Add After that:
mDInputInterface->EnumDevices( DI8DEVTYPE_GAMEPAD, EnumDevicesProc, this, DIEDFL_ATTACHEDONLY );
In winDInputDevice.cc: DInputDevice( const DIDEVICEINSTANCE* dii )
Find:
case DI8DEVTYPE_JOYSTICK:
Change to:
case DI8DEVTYPE_JOYSTICK:
case DI8DEVTYPE_GAMEPAD:
That should do it. Search the forums for POV hat if you want to find out how to enable that too.
01/11/2006 (7:14 pm)
For anyone else who cares:To get gamepads (and possibly others) working:
In winDirectInput.cc: enumerateDevices()
Find:
mDInputInterface->EnumDevices( DI8DEVTYPE_JOYSTICK, EnumDevicesProc, this, DIEDFL_ATTACHEDONLY );
Add After that:
mDInputInterface->EnumDevices( DI8DEVTYPE_GAMEPAD, EnumDevicesProc, this, DIEDFL_ATTACHEDONLY );
In winDInputDevice.cc: DInputDevice( const DIDEVICEINSTANCE* dii )
Find:
case DI8DEVTYPE_JOYSTICK:
Change to:
case DI8DEVTYPE_JOYSTICK:
case DI8DEVTYPE_GAMEPAD:
That should do it. Search the forums for POV hat if you want to find out how to enable that too.
#13
I have downloaded the October 2005 version of the DirectX9.0 SDK. Any ideas?
01/15/2006 (6:58 pm)
I tried compiling your Gamepad changes in with the Alpha version of T2D. I get an error that it cannot find xinput.hI have downloaded the October 2005 version of the DirectX9.0 SDK. Any ideas?
#14
It works fine when I run the packaged examples.
01/15/2006 (8:52 pm)
Okay, I compiled it okay, apparently I didn't get the SDK before. But now when I try and run the game I can't use my XBox 360 controller. I'm getting a "XInput failed to enable!" error in the log file. I'm running windows 2000. Any idea what's going on?It works fine when I run the packaged examples.
#15
So, you are saying you took the source code for the controllers and overlaid it on top of the alpha? You also installed DX Oct 2005, and you did a full rebuild? There's only one way that "XInput failed to enable!" can occur: your build is unable to bind to the XInput9_1_0.dll is not installed... can you check to see that it is?
Are you sure you installed the Xbox 360 controller driver?
When you say "It works fine when I run the packaged examples", do you mean my compiled exe that I distributed is working on the same machine?
01/16/2006 (1:27 am)
Sorry, I guess I need more info.So, you are saying you took the source code for the controllers and overlaid it on top of the alpha? You also installed DX Oct 2005, and you did a full rebuild? There's only one way that "XInput failed to enable!" can occur: your build is unable to bind to the XInput9_1_0.dll is not installed... can you check to see that it is?
Are you sure you installed the Xbox 360 controller driver?
When you say "It works fine when I run the packaged examples", do you mean my compiled exe that I distributed is working on the same machine?
#16
I'm planning to use "standard" joystick in my game
(I would like to run on Macs too)
I was playing with the estandar joystick and I could
detect a boton pressed, after restarting T2D the game
was crashing just when the joystick is enabled,
somebody has any advice?
01/19/2006 (12:59 pm)
Hello.I'm planning to use "standard" joystick in my game
(I would like to run on Macs too)
I was playing with the estandar joystick and I could
detect a boton pressed, after restarting T2D the game
was crashing just when the joystick is enabled,
somebody has any advice?
#17
look up his profile.
01/19/2006 (1:06 pm)
I know that Jessie Hall has got a generic gamepad working pretty well with T2D, you could try emailing him.look up his profile.
Torque Owner Jason Cahill
Default Studio Name
This link