简体   繁体   English

在Visual Studio中使用Xbox One控制器?

[英]Using an Xbox One controller in Visual Studio?

I am trying to get input from an Xbox One controller, but I just cannot get it to work. 我试图从Xbox One控制器获取输入,但我无法让它工作。 I tried SharpDX, but I could not add "SharpDX.XInput" after installing SharpDX from NuGet. 我尝试过SharpDX,但是在从NuGet安装SharpDX后我无法添加“SharpDX.XInput”。 I also tried XInputDotNet, and added the reference to XInputDotNetPure, and it would crash when I ran my program, with the error message: "An attempt was made to load a program with an incorrect format". 我还尝试了XInputDotNet,并添加了对XInputDotNetPure的引用,当我运行程序时它会崩溃,并显示错误消息:“试图加载程序格式不正确”。 If you know how I could fix this, or another way to get input from an Xbox One controller, I would greatly appreciate it if you could share that with me. 如果您知道如何解决这个问题,或者从Xbox One控制器获取输入的其他方式,如果您能与我分享,我将非常感激。 Thanks! 谢谢!

Used the Sharpdx.XInput interface. 使用Sharpdx.XInput接口。 You don't need to install any other interface to get XBOX controllers working. 您无需安装任何其他界面即可使XBOX控制器正常工作。 There is an issue with install in 3.0 packages if you have win 8.1. 如果您获胜8.1,则在3.0软件包中安装会出现问题。 A new beta V4.0 was released, you should be able to get this through Nuget if you enable beta flag. 一个新的测试版V4.0已经发布,如果你启用了beta标志,你应该可以通过Nuget获得这个。

Declare a Controller Object 声明一个Controller对象

eg. 例如。

private Controller m_playerControl;

in your creation, use 在你的创作中,使用

 m_playerControl = new Controller(UserIndex.One); 

or 2 etc 3, 4 或2等3,4

You can test if the xbox controller is connected with: 您可以测试xbox控制器是否已连接:

m_playerControl.IsConnected

To grab the state. 抓住国家。

  m_state = m_playerControl.GetState();
        m_lx = m_state.Gamepad.LeftThumbX;
        m_ly = m_state.Gamepad.LeftThumbY;
        m_lt = m_state.Gamepad.LeftTrigger;
        m_lb = m_state.Gamepad.Buttons;

        m_rx = m_state.Gamepad.RightThumbX;
        m_ry = m_state.Gamepad.RightThumbY;
        m_rt = m_state.Gamepad.RightTrigger;

Advise you also use the same state object and overlay your gamepads etc. 建议你也使用相同的状态对象并覆盖你的游戏手柄等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM