【问题标题】:How to use DirectX.DirectInput in XNA如何在 XNA 中使用 DirectX.DirectInput
【发布时间】:2011-08-02 01:08:37
【问题描述】:

joystick.cs

using System;
using Microsoft.DirectX.DirectInput;

namespace gameproject
{
    /// <summary>
    /// Description of device.
    /// </summary>
    class joysticks
    {

        public static Device joystick;
        public static JoystickState state;

        public static void InitDevices() //Function of initialize device
        {
            //create joystick device.
            foreach (DeviceInstance di in Manager.GetDevices(
                DeviceClass.GameControl,
                EnumDevicesFlags.AttachedOnly))
            {
                joystick = new Device(di.InstanceGuid);
                break;
            }

            if (joystick == null)
            {
                //Throw exception if joystick not found.
            }

            //Set joystick axis ranges.
            else {
                foreach (DeviceObjectInstance doi in joystick.Objects)
                {
                    if ((doi.ObjectId & (int)DeviceObjectTypeFlags.Axis) != 0)
                    {
                        joystick.Properties.SetRange(
                            ParameterHow.ById,
                            doi.ObjectId,
                            new InputRange(-5000, 5000));
                    }

                }

                joystick.Properties.AxisModeAbsolute = true;
                joystick.SetCooperativeLevel(null,CooperativeLevelFlags.NonExclusive | CooperativeLevelFlags.Background);

                //Acquire devices for capturing.
                joystick.Acquire();
                state = joystick.CurrentJoystickState;
            }
        }

        public static void UpdateJoystick()   // Capturing from device joystick
        {
            //Get Joystick State.
            if(joystick!=null)
                state = joystick.CurrentJoystickState;
        }

    }
}

在这一行,发生了错误,

    joystick.SetCooperativeLevel(null,CooperativeLevelFlags.NonExclusive 
| CooperativeLevelFlags.Background);

错误,

Error 1 The type 'System.Windows.Forms.Control' is defined in an 
assembly that is not referenced.
     You must add a reference to assembly 'System.Windows.Forms...

我正在开发 XNA 3.0 和 .NET 3.5,那么这个错误是什么意思?

【问题讨论】:

    标签: c# xna directx joystick xna-3.0


    【解决方案1】:

    SetCooperativeLevelSystem.Windows.Forms.Control 对象作为第一个参数(您有 null),因此您仍应引用在应用程序中定义此类的程序集。从您的应用程序/游戏中添加引用 do System.Windows.Forms.dll 然后尝试。如果您使用的代码正在使用您未在后台引用的其他一些类,那没关系,但是当它们是公共的(例如它们是参数或从您正在调用的方法返回)时,您必须引用其中的程序集这些类型已定义。

    类似的stackoverflow帖子: Debugging error "The Type 'xx' is defined in an assembly that is not referenced"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-07
      • 1970-01-01
      • 2010-09-21
      • 2011-03-02
      • 2010-11-01
      • 2012-01-06
      相关资源
      最近更新 更多