如何使用DirectX.DirectInput在XNA [英] How to use DirectX.DirectInput in XNA

查看:187
本文介绍了如何使用DirectX.DirectInput在XNA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

joystick.cs

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...



我M工作,XNA 3.0和.NET 3.5,所以有什么意味着错误?

I'm working on,XNA 3.0 and .NET 3.5, so what means that error?

推荐答案

SetCooperativeLevel 需要 System.Windows。 Forms.Control 对象作为第一个参数(如果你有空),所以你还是应该在这里引用这个类是在应用程序中定义的组件。添加引用您的应用程序/游戏做System.Windows.Forms.dll程序,并尝试呢。如果代码使用的是正在使用,你有没有引擎盖下中引用的一些其他类,它的确定,但是,当他们是公共的(像他们的参数或您所呼叫的方法返回),你必须引用程序集在其中这些类型的定义。

SetCooperativeLevel takes System.Windows.Forms.Control object as a first parameter (where you have null), so you should still reference assembly where this class is defined in your application. Add reference do System.Windows.Forms.dll from your app/game and try then. If code you are using is using some other classes that you haven't referenced under the hood, it's ok, but when they are public (like they are parameter or are returned from methods you are calling), you have to reference assemblies in which those types are defined.

类似计算器后是自定义的 - 在一个组装 - 这 - 是 - 不引用>调试错误"该类型'xx'是在不引用"程序集中定义;

Similar stackoverflow post: Debugging error "The Type 'xx' is defined in an assembly that is not referenced"

这篇关于如何使用DirectX.DirectInput在XNA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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