Example #1
0
        public static GamePadState GetAsGamePadState(int joystickIndex, JoystickAssingn assign /* = null*/)
        {
            JoystickState joyState = GetAsJoystickState(joystickIndex);

            if (!joyState.IsConnected)
            {
                return(new GamePadState());
            }

            if (assign == null)
            {
                assign = JoystickAssingn.Default;
            }

            Buttons buttons = (Buttons)0;

            for (int i = 0; i < JoystickAssingn.NumButtons; ++i)
            {
                int bit = 1 << i;
                if ((joyState.Buttons & bit) != 0)//joyState.Buttons & bit) != 0)
                {
                    buttons |= assign.ButtonMap[i];
                }
            }

            return(new GamePadState(
                       new GamePadThumbSticks(
                           new Vector2(assign.LeftThumbstickX.GetValue(ref joyState), assign.LeftThumbstickY.GetValue(ref joyState)),
                           new Vector2(assign.RightThumbstickX.GetValue(ref joyState), assign.RightThumbstickY.GetValue(ref joyState))),
                       new GamePadTriggers(
                           assign.LeftTrigger.GetValue(ref joyState),
                           assign.RightTrigger.GetValue(ref joyState)),
                       new GamePadButtons(buttons), joyState.DPad));
        }
        public static GamePadState GetAsGamePadState(int joystickIndex, JoystickAssingn assign/* = null*/)
        {
            JoystickState joyState = GetAsJoystickState(joystickIndex);

            if (!joyState.IsConnected)
            {
                return new GamePadState();
            }

            if (assign == null)
            {
                assign = JoystickAssingn.Default;
            }

            Buttons buttons = (Buttons)0;

            for (int i = 0; i < JoystickAssingn.NumButtons; ++i)
            {
                int bit = 1 << i;
                if ((joyState.Buttons & bit) != 0)//joyState.Buttons & bit) != 0)
                {
                    buttons |= assign.ButtonMap[i];
                }
            }

            return new GamePadState(
                new GamePadThumbSticks(
                    new Vector2(assign.LeftThumbstickX.GetValue(ref joyState),assign.LeftThumbstickY.GetValue(ref joyState)),
                    new Vector2(assign.RightThumbstickX.GetValue(ref joyState),assign.RightThumbstickY.GetValue(ref joyState))),
                new GamePadTriggers(
                    assign.LeftTrigger.GetValue(ref joyState),
                    assign.RightTrigger.GetValue(ref joyState)),
                new GamePadButtons(buttons), joyState.DPad);
        }