SlimDx多个操纵杆问题 [英] SlimDx Multiple joystick issue

查看:60
本文介绍了SlimDx多个操纵杆问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SlimDx在我的c#app中获取操纵杆反馈。我实现的代码适用于一根棒,但我似乎无法获得两个相同的棒。我提前为你的无知道歉。以下是代码:



Im using SlimDx to pick up joystick feedback in my c# app. The code I implemented works fine for one stick but I cant seem to get two identical sticks to work. Apologies for my ignorance ahead of time. Here is the code:

public SimpleJoystick()
{

DirectInput dinput = new DirectInput();

foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController,                                                  DeviceEnumerationFlags.AttachedOnly))
            {

                // Create device
                  try
                  {
                     stickOne = new Joystick(dinput, device.InstanceGuid);

                    break;
                  }



                catch (DirectInputException)
                {
                   //catch stuff here
                }
 }



在此之前我已经制作了一个名为棍棒的Joystick []。如何将每个设备放入foreach循环中的操纵杆阵列?我无法弄清楚可以在stick [x]中使用哪个变量,以便它对应于棒的正确InstanceGuid。任何帮助都是最受欢迎的。


Ive made a Joystick[] named sticks prior to this. How do I place each device into the Joystick array within the foreach loop? I cant figure out what variable can be used in the sticks[x] so that it corresponds to the correct InstanceGuid of the stick. Any help would be most appreciated.

推荐答案

除非你出于某种原因必须使用数组,否则你会最好使用其中一个通用集合。



A 列表<操纵杆> ,例如。然后您就可以替换:

Unless you have to use an Array for some reason, you would be better using one of the generic collections.

A List<Joystick>, for example. You would then be able to replace:
stickOne = new Joystick(dinput, device.InstanceGuid);





with(假设您将列表 stick 称为你的数组)



with (assume you called the list sticks as in your array)

sticks.Add(new Joystick(dinput, device.InstanceGuid));





甚至是字典



Or even a dictionary

Dictionary<GUID, Joystick> sticks = new Dictionary<GUID, Joystick>();

// then in the try block
sticks.Add(device.InstanceGuid, new Joystick(dinput, device.InstanceGuid));





如果需要,您可以通过GUID查找它们。



You would then be able to look them up by their GUID, if that is required.


这篇关于SlimDx多个操纵杆问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆