Jump to content

  • Log In with Google      Sign In   
  • Create Account


XNA custom gamepads in Visual Studio


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Metrospecies   Members   -  Reputation: 102

Like
0Likes
Like

Posted 03 August 2012 - 03:14 AM

Heres a question, is it possible to use a non 360 for windows controller?

I have a fairly cheap one that i would like to use for game development, but it isn't registered by visual studio.

Also http://code.google.com/p/x360ce/ is an emulator for non 360 controllers by putting the files in the main folder, however it doesn't read in Visual Studio 2010's main folder, would i have to be more specific and put it in the main XNA folder?

Cheers

Sponsor:

#2 Kasc   Members   -  Reputation: 119

Like
0Likes
Like

Posted 03 August 2012 - 08:21 AM

Use SlimDX's direct input library, you access the joystick like so:

[source lang="csharp"] Joystick joystick; int joystickButtonCount; int joystickAxesCount; JoystickState joystickState, oldJoystickState; public Game() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; CreateDevice(); } ... protected override void Update(GameTime gameTime) { joystickState = joystick.GetCurrentState(); bool[] buttons = joystickState.GetButtons(); Console.Clear(); Console.WriteLine("Using device: {0}\nButton count: {1}\nAxes count: {2}\n", joystick.Information.ProductName, joystickButtonCount, joystickAxesCount); for (int i = 0; i < joystickButtonCount; i++) { Console.WriteLine("{0}: {1}", i + 1, buttons[i]); } } void CreateDevice() { DirectInput dinput = new DirectInput(); foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly)) { try { joystick = new Joystick(dinput, device.InstanceGuid); joystickAxesCount = joystick.Capabilities.AxesCount; joystickButtonCount = joystick.Capabilities.ButtonCount; break; } catch { } } if (joystick == null) { Console.WriteLine("No devices"); return; ; } joystick.Acquire(); foreach (DeviceObjectInstance deviceObject in joystick.GetObjects()) { if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0) joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-1000, 1000); } }[/source]

Getting your axis information is a little different, if you do joystickState{dot} intellisense will show you a lot of properties, the ones with X, Y and Z on the end will give you your axis info, so to find out which one your joystick uses you'll have to print them all the console and see.

EDIT:

These two lines:

joystickAxesCount = joystick.Capabilities.AxesCount;
joystickButtonCount = joystick.Capabilities.ButtonCount;

may cause you to hang for a few seconds, so you may want to create your device on a seperate thread so your main game loop won't stall until it responds. You could also cut this out entirely and loop over the entire bool[] buttons array which I think is of size 128.

Edited by Kasc, 03 August 2012 - 08:25 AM.


#3 6677   Members   -  Reputation: 1058

Like
0Likes
Like

Posted 03 August 2012 - 09:52 AM

Also http://code.google.com/p/x360ce/ is an emulator for non 360 controllers by putting the files in the main folder, however it doesn't read in Visual Studio 2010's main folder, would i have to be more specific and put it in the main XNA folder?

This isn't really a visual studio issue, the program is for standalone applications that have already been compiled.

http://code.google.c...e/wiki/MainPage

Compile your game then dependant on whether you compiled in debug or release mode go to:
My Documents>Visual Studio 2010> Projects>[project name]>[project name]>bin>[either debug or release]
That is your games folder that you install x360ce in. You may have to manually copy you xinput.dll file which should be in program files on your hard drive somewhere.

I tried that program out, found I had about half a second delay on inputs whereas by actual 360 pad runs fine.


As for the actual 360 gamepads, its well worth buying one. £20 for a wired USB gamepad with the functionality and quality to match gamepads costing far more. Just can't really argue with it.

Edited by 6677, 03 August 2012 - 09:55 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS