コード例 #1
0
        /// <summary>
        /// Check if the player has a game pad connected if
        /// so this method creates the code for one.
        /// </summary>
        /// <returns>The result of the check.</returns>
        public static bool CheckCreateGamePad()
        {
            if (gamePad == null)
            {
                GamePadState state     = default(GamePadState);
                bool         connected = false;

                int playerIndex = 0;

                while (!connected && playerIndex < 4)
                {
                    state = Microsoft.Xna.Framework.Input.GamePad.GetState((Microsoft.Xna.Framework.PlayerIndex)playerIndex);

                    if (state.IsConnected)
                    {
                        connected = true;
                        gamePad   = new Input.GamePad((PlayerIndex)playerIndex);
                    }
                    else
                    {
                        playerIndex++;
                    }
                }

                return(connected);
            }

            return(true);
        }
コード例 #2
0
        internal static void CurrentGamePadDisconnected()
        {
            gamePad.Destroy();
            gamePad = null;

            wasGamePadConnected = true;

            if (OnGamePadDisconnected != null)
            {
                OnGamePadDisconnected();
            }
        }
コード例 #3
0
        public void _Update()
        {
            if (gamePad == null && wasGamePadConnected)
            {
                int  idx       = 0;
                bool connected = false;

                while (idx < 4 && !connected)
                {
                    connected = Microsoft.Xna.Framework.Input.GamePad.GetState(
                        (Microsoft.Xna.Framework.PlayerIndex)idx).IsConnected;

                    idx++;
                }

                gamePad = new Input.GamePad((PlayerIndex)idx);
            }
        }