Search code examples
c#xnadirectinput

Game Wont Start


I'm using DirectInput with XNA however for some strange reason my game will not start when I have the following code implemented:

DeviceList gameControllerList = Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly);

That really breaks my game, commenting the line works though leaving it in breaks it. I have absolutely no idea why. I have Microsoft.DirectX.DirectInput referenced and everything. I even started a whole new project and just entered that line but had no luck in the game starting up.

This is literally my complete code, I just call Input.InitializeController() from the initialize method in Game1().

using System;
using Microsoft.DirectX.DirectInput;

namespace InputTesting{
    class Input{
        public void InitializeController(){
            DeviceList gameControllerList = Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly);
        }
    }
}

Does anyone know what the deal is with this I am completely stumped.

Thanks!


Solution

  • If you're using XNA 4.0 then your problem is due to XNA not supporting DirectInput properly.

    In order to get your device working with your program you'll need to either roll back to XNA 3.1 or use a wrapper that allows Direct Input in 4.0, I'd recommend going with the wrapper SlimDX.