コード例 #1
0
        public XboxController() {

            // Initialize Buttons
            Buttons = new XboxButton[14];
            Buttons[0] = new XboxButton(OnButtonAPressed, OnButtonAReleased);
            Buttons[1] = new XboxButton(OnButtonBPressed, OnButtonBReleased);
            Buttons[2] = new XboxButton(OnButtonXPressed, OnButtonXReleased);
            Buttons[3] = new XboxButton(OnButtonYPressed, OnButtonYReleased);
            Buttons[4] = new XboxButton(OnButtonStartPressed, OnButtonStartReleased);
            Buttons[5] = new XboxButton(OnButtonBackPressed, OnButtonBackReleased);
            Buttons[6] = new XboxButton(OnButtonLeftShoulderPressed, OnButtonLeftShoulderReleased);
            Buttons[7] = new XboxButton(OnButtonRightShoulderPressed, OnButtonRightShoulderReleased);
            Buttons[8] = new XboxButton(OnThumbStickLeftPressed, OnThumbStickLeftReleased);
            Buttons[9] = new XboxButton(OnThumbStickRightPressed, OnThumbStickRightReleased);
            Buttons[10] = new XboxButton(OnDPadUpPressed, OnDPadUpReleased);
            Buttons[11] = new XboxButton(OnDPadDownPressed, OnDPadDownReleased);
            Buttons[12] = new XboxButton(OnDPadLeftPressed, OnDPadLeftReleased);
            Buttons[13] = new XboxButton(OnDPadRightPressed, OnDPadRightReleased);

            // Initialize Triggers
            Triggers = new XboxTrigger[2];
            Triggers[0] = new XboxTrigger(OnTriggerLeftChanged);
            Triggers[1] = new XboxTrigger(OnTriggerRightChanged);

            // Initialize ThumbSticks
            ThumbSticks = new XboxThumbStick[2];
            ThumbSticks[0] = new XboxThumbStick(OnThumbStickLeftChanged);
            ThumbSticks[1] = new XboxThumbStick(OnThumbStickRightChanged);

            Thread t = new Thread(x => { while (true) Listen(); });
            t.Start();
        }
コード例 #2
0
        /// <summary>
        /// Checks if the thumbstick has changed, returning true if it has, false otherwise.
        /// </summary>
        private bool CheckThumbStick(Vector2 stick, XboxThumbStick ThumbStick) {
            if (ThumbStick == null)
                return false;

            if (stick.X != ThumbStick.Vector.X) {
                ThumbStick.Vector = new Vector2(stick.X, stick.Y);
                return true;
            }
            else if (stick.Y != ThumbStick.Vector.Y) {
                ThumbStick.Vector = new Vector2(stick.X, stick.Y);
                return true;
            }
            return false;
        }