当前位置: 首页>>代码示例>>C#>>正文


C# InputState.IsNewButtonPress方法代码示例

本文整理汇总了C#中GameStateManagement.InputState.IsNewButtonPress方法的典型用法代码示例。如果您正苦于以下问题:C# InputState.IsNewButtonPress方法的具体用法?C# InputState.IsNewButtonPress怎么用?C# InputState.IsNewButtonPress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GameStateManagement.InputState的用法示例。


在下文中一共展示了InputState.IsNewButtonPress方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HandleInput

        public override void HandleInput(InputState input)
        {
            PlayerIndex player;
            if (input.IsNewButtonPress(Buttons.Y, ControllingPlayer, out player))
            {
            #if XBOX
                Debug.Assert (ControllingPlayer != null);
                HighScores2.GoLoad(ControllingPlayer ?? PlayerIndex.One);
            #else

                HighScores2.DoWindowsLoadGame();
            #endif

                ScreenManager.AddScreen(new HighScoreScreen(), ControllingPlayer);
            }

            if (input.IsMenuCancel(ControllingPlayer, out player))
            {
                MediaPlayer.Stop();
            }

            songSelectionBox.HandleInput(input);
            if (songSelectionBox.SongCount <= 0 &&
                input.IsNewButtonPress(Buttons.A, null, out player))
            {
                return;
            }
            base.HandleInput(input);
        }
开发者ID:kmatzen,项目名称:EECS-494-Final-Project,代码行数:29,代码来源:SongSelectionScreen.cs

示例2: HandleInput

        public override void HandleInput(InputState input)
        {
            // cancel the current screen if the user presses the back button
            PlayerIndex player;
            if (input.IsNewButtonPress(Buttons.Back, null, out player))
            {
                ExitScreen();
            }

            if(RootControl != null)
                RootControl.HandleInput(input);

            base.HandleInput(input);
        }
开发者ID:agentcox,项目名称:NodeHackEX-xna,代码行数:14,代码来源:SingleControlScreen.cs

示例3: HandleInput

        /// <summary>
        /// Lets the game respond to player input. Unlike the Update method,
        /// this will only be called when the gameplay screen is active.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            if (input == null)
                throw new ArgumentNullException("input");

            // Look up inputs for the active player profile.
            int playerIndex = (int)ControllingPlayer.Value;

            KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex];
            GamePadState gamePadState = input.CurrentGamePadStates[playerIndex];

            List<GestureSample> gestures = input.Gestures;
            foreach (GestureSample gs in input.Gestures)
            {
                if (gs.GestureType == GestureType.Tap)
                {
                    if (p1s.destinationBox.Contains((int)gs.Position.X, (int)gs.Position.Y))
                    {
                        currentPlayerIndex = 0;
                    }
                    else if (p2s.destinationBox.Contains((int)gs.Position.X, (int)gs.Position.Y))
                    {
                        currentPlayerIndex = 1;
                    }
                    else if (p3s.destinationBox.Contains((int)gs.Position.X, (int)gs.Position.Y))
                    {
                        currentPlayerIndex = 2;
                    }
                }
            }

            if (input.TouchState.Count == 0)
            {
                players[currentPlayerIndex].velocity = new Vector2(0, 0);
            }
            foreach (TouchLocation touch in input.TouchState)
            {
                //Vector2 position = gs.Position;
                if ((touch.State == TouchLocationState.Pressed
                        || touch.State == TouchLocationState.Moved))
                {
                    CheckForMovement(touch.Position);
                    break;
                }
            }
            // if the user pressed the back button, we return to the main menu
            PlayerIndex player;
            if (input.IsNewButtonPress(Buttons.Back, ControllingPlayer, out player))
            {
                LoadingScreen.Load(ScreenManager, false, ControllingPlayer, new BackgroundScreen(), new MainMenuScreen());
            }
        }
开发者ID:holste10,项目名称:Army_of_Three,代码行数:56,代码来源:GameplayScreen.cs

示例4: HandleInput

        public override void HandleInput(InputState input)
        {
            //base.HandleInput(input);
            PlayerIndex junk;
            for (int i = 0; i < 4; i++)
            {
                //If the player hit A to join
                if (input.IsNewButtonPress(Buttons.A, (PlayerIndex)i, out junk) && !towersmash.players[i])
                {
                    towersmash.players[i] = true;
                }
                    //else if the player hit B to leave
                else if (input.IsNewButtonPress(Buttons.B, (PlayerIndex)i, out junk) && towersmash.players[i])
                {
                    towersmash.players[i] = false;
                }
                //If the player moves up the list
                if (towersmash.players[i] && input.IsNewButtonPress(Buttons.RightShoulder, (PlayerIndex)i, out junk))
                {
                    player_selection[i]++;
                    if (player_selection[i] > character_number)
                        player_selection[i] = 0;
                }
                //If the player moves down the list
                if (towersmash.players[i] && input.IsNewButtonPress(Buttons.LeftShoulder, (PlayerIndex)i, out junk))
                {
                    player_selection[i]--;
                    if (player_selection[i] < 0)
                        player_selection[i] = character_number;
                }
            }
            //If anyone wants to start the game
            if(input.IsNewButtonPress(Buttons.Start, null, out junk))
            {
                towersmash.updatenumberofplayers();
                if (towersmash.numberofplayers > 1)
                {
                    base.OnCancel(junk);
                    LoadingScreen.Load(ScreenManager, true, junk, new pvp(ScreenManager));
                }
                else
                {
                    MessageBoxScreen messagebox = new MessageBoxScreen("Must have at least 2 players ready for battle!");
                    ScreenManager.AddScreen(messagebox, null);
                }
            }
            //If anyone wants to go back to the main menu
            if (input.IsNewButtonPress(Buttons.Back, null, out junk))
            {
                base.OnCancel(junk);
            }

            //Quick hack for me on the keyboard
            if (input.IsNewKeyPress(Keys.Enter, null, out junk))
            {
                towersmash.numberofplayers = 2;
                towersmash.players[0] = true;
                towersmash.players[1] = true;
                towersmash.players[2] = false;
                towersmash.players[3] = false;
                towersmash.characters[0] = playertype.bashy;
                towersmash.characters[1] = playertype.shifty;
                base.OnCancel(junk);
                LoadingScreen.Load(ScreenManager, true, junk, new pvp(ScreenManager));
            }
        }
开发者ID:danielselnick,项目名称:Sentry-Smash,代码行数:66,代码来源:playerselect.cs

示例5: HandleInput

        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            // we cancel the current menu screen if the user presses the back button
            PlayerIndex player;
            if (input.IsNewButtonPress(Buttons.Back, ControllingPlayer, out player))
            {
                LoadingScreen.Load(ScreenManager, false, ControllingPlayer, new MenuBackgroundScreen("mainMenubackground"), new MainMenuScreen());
            }

            // look for any taps that occurred and select any entries that were tapped
            foreach (GestureSample gesture in input.Gestures)
            {
                if (gesture.GestureType == GestureType.Tap)
                {
                    // convert the position to a Point that we can test against a Rectangle
                    Point tapLocation = new Point((int)gesture.Position.X, (int)gesture.Position.Y);

                    // iterate the entries to see if any were tapped
                    for (int i = 0; i < levelEntries.Count; i++)
                    {
                        LevelEntry lvlEntry = levelEntries[i];

                        if (GetMenuEntryHitBounds(lvlEntry).Contains(tapLocation))
                        {
                            if (lvlEntry.starsDisplayed != Stars.LOCKED)
                            {
                                // select the entry. since gestures are only available on Windows Phone,
                                // we can safely pass PlayerIndex.One to all entries since there is only
                                // one player on Windows Phone.
                                OnSelectEntry(i, PlayerIndex.One);
                            }
                            else
                            {
                                Debug.WriteLine("Level locked");
                            }
                        }
                    }
                }
                if (gesture.GestureType == GestureType.HorizontalDrag)
                {
                    TransitionPosition = -(float)gesture.Delta.X*0.1f;
                    if (gesture.Delta.X >= 10)
                    {
                        IsExiting = true;
                    }
                    else if (gesture.Delta.X <= -10)
                    {
                        IsExiting = true;
                    }
                    Debug.WriteLine(gesture.Delta.X);
                }
            }
        }
开发者ID:skakri09,项目名称:WinPhone-menuSystem,代码行数:57,代码来源:LevelSelectorScreen.cs

示例6: HandleInput

        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            // we cancel the current menu screen if the user presses the back button
            PlayerIndex player;
            if (input.IsNewButtonPress(Buttons.Back, ControllingPlayer, out player))
            {
                OnCancel(player);
            }
#if WINDOWS
            // Take care of Keyboard input
            if (input.IsMenuUp(ControllingPlayer))
            {
                selectedEntry--;

                if (selectedEntry < 0)
                    selectedEntry = menuEntries.Count - 1;
            }
            else if (input.IsMenuDown(ControllingPlayer))
            {
                selectedEntry++;

                if (selectedEntry >= menuEntries.Count)
                    selectedEntry = 0;
            }
            else if (input.IsNewKeyPress(Keys.Enter, ControllingPlayer, out player) ||
                input.IsNewKeyPress(Keys.Space, ControllingPlayer, out player))
            {
                OnSelectEntry(selectedEntry, player);
            }


            MouseState state = Mouse.GetState();
            if (state.LeftButton == ButtonState.Released)
            {
                if (isMouseDown)
                {
                    isMouseDown = false;
                    // convert the position to a Point that we can test against a Rectangle
                    Point clickLocation = new Point(state.X, state.Y);

                    // iterate the entries to see if any were tapped
                    for (int i = 0; i < menuEntries.Count; i++)
                    {
                        MenuEntry menuEntry = menuEntries[i];

                        if (menuEntry.Destination.Contains(clickLocation))
                        {
                            // Select the entry. since gestures are only available on Windows Phone,
                            // we can safely pass PlayerIndex.One to all entries since there is only

                            // one player on Windows Phone.
                            OnSelectEntry(i, PlayerIndex.One);
                        }
                    }
                }
            }
            else if (state.LeftButton == ButtonState.Pressed)
            {
                isMouseDown = true;

                // convert the position to a Point that we can test against a Rectangle
                Point clickLocation = new Point(state.X, state.Y);

                // iterate the entries to see if any were tapped
                for (int i = 0; i < menuEntries.Count; i++)
                {
                    MenuEntry menuEntry = menuEntries[i];

                    if (menuEntry.Destination.Contains(clickLocation))
                        selectedEntry = i;
                }
            }
#elif XBOX
            // Take care of Gamepad input
            if (input.IsMenuUp(ControllingPlayer))
            {
                selectedEntry--;

                if (selectedEntry < 0)
                    selectedEntry = menuEntries.Count - 1;
            }
            else if (input.IsMenuDown(ControllingPlayer))
            {
                selectedEntry++;

                if (selectedEntry >= menuEntries.Count)
                    selectedEntry = 0;
            }
            else if (input.IsNewButtonPress(Buttons.A, ControllingPlayer, out player))
                OnSelectEntry(selectedEntry, player);

#elif WINDOWS_PHONE
            // look for any taps that occurred and select any entries that were tapped
            foreach (GestureSample gesture in input.Gestures)
            {
                if (gesture.GestureType == GestureType.Tap)
//.........这里部分代码省略.........
开发者ID:liwq-net,项目名称:SilverSprite,代码行数:101,代码来源:MenuScreen.cs

示例7: HandleInput

        /// <summary>
        /// Lets the game respond to player input. Unlike the Update method,
        /// this will only be called when the gameplay screen is active.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            if (input == null)
                throw new ArgumentNullException("input");

            // Look up inputs for the active player profile.

            int playerIndex = (int)ControllingPlayer.Value;
            KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex];
            GamePadState gamePadState = input.CurrentGamePadStates[playerIndex];

            // if the user pressed the back button, we return to the main menu
            PlayerIndex player;
            if (input.IsNewButtonPress(Buttons.Back, ControllingPlayer, out player))
            {
                //LoadingScreen.Load(ScreenManager, false, ControllingPlayer, new MenuBackgroundScreen(), new MainMenuScreen());
                ScreenManager.AddScreen(new GameOptionsMenuScreen(), player);
            }

            //Input that affects the gameplay
            CheckForMovement(input);
            CheckForCharacterSwitch(input);
            CheckForAbilitiesUse(input);
        }
开发者ID:skakri09,项目名称:GameOfThreetards,代码行数:28,代码来源:GameplayScreen.cs

示例8: HandleInput

        /// <summary>
        /// Lets the game respond to player input. Unlike the Update method,
        /// this will only be called when the gameplay screen is active.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            if (input == null)
                throw new ArgumentNullException("input");

            // Look up inputs for the active player profile.
            int playerIndex = (int)ControllingPlayer.Value;

            // if the user pressed the back button, we return to the main menu
            PlayerIndex player;
            if (input.IsNewButtonPress(Buttons.Back, ControllingPlayer, out player))
            {
                LoadingScreen.Load(ScreenManager, false, ControllingPlayer, new BackgroundScreen(), new MainMenuScreen());
            }
            else
            {
                // Otherwise move the player position.
                Vector2 movement = Vector2.Zero;

                if (movement.Length() > 1)
                    movement.Normalize();

                playerPosition += movement * 2;
            }

            ////My stuff
            var mouseState = Mouse.GetState();

            if (mouseState.LeftButton == ButtonState.Pressed)
            {

                ///MathHelper.Clamp(player1.position.Y, 0, 10f);

                if (mouseState.Y < 400)
                {
                    player1.isFlip = true;
                    player1.position.Y = 5;
                    player1.position.X = mouseState.X - player1.texture.Width / 2;

                }
                else
                {
                    player1.position.X = mouseState.X - player1.texture.Width / 2;
                    player1.position.Y = 770f;
                    player1.isFlip = false;

                }

            }
        }
开发者ID:sagarpatel,项目名称:CSGames2011,代码行数:54,代码来源:GameplayScreen.cs

示例9: HandleInput

        public void HandleInput(InputState input)
        {
            int oldSelected = selected;
            int oldLibrary = libraryIndex;

            if (input.IsMenuDown(screen.ControllingPlayer))
            {
                if (selected < library.Count - 1)
                {
                    ++selected;
                    if (selected == numEntries + index)
                    {
                        ++index;
                    }
                    loadAroundIndex(selected);
                }
            }
            if (input.IsMenuUp(screen.ControllingPlayer))
            {
                if (selected > 0)
                {
                    --selected;
                    if (selected == index - 1)
                    {
                        --index;
                    }
                    loadAroundIndex(selected);
                }
            }

            PlayerIndex player;

            if (input.IsNewButtonPress(Buttons.X, screen.ControllingPlayer, out player))
            {
                MediaPlayer.Play(library[selected]);
            }

            if (input.IsNewButtonPress(Buttons.LeftShoulder, screen.ControllingPlayer, out player) ||
                input.IsNewKeyPress(Keys.Left, screen.ControllingPlayer, out player))
            {
                if (libraryIndex > 0)
                {
                    --libraryIndex;
                    mediaSourceName = MediaSource.GetAvailableMediaSources()[libraryIndex].Name;
                    library = new MediaLibrary(MediaSource.GetAvailableMediaSources()[libraryIndex]).Songs;
                    index = 0;
                    selected = 0;
                    initializeSongDataArray();
                }
            }
            if (input.IsNewButtonPress(Buttons.RightShoulder, screen.ControllingPlayer, out player) ||
                input.IsNewKeyPress(Keys.Right, screen.ControllingPlayer, out player))
            {
                if (libraryIndex < MediaSource.GetAvailableMediaSources().Count - 1)
                {
                    ++libraryIndex;
                    mediaSourceName = MediaSource.GetAvailableMediaSources()[libraryIndex].Name;
                    library = new MediaLibrary(MediaSource.GetAvailableMediaSources()[libraryIndex]).Songs;
                    index = 0;
                    selected = 0;
                    initializeSongDataArray();
                }
            }

            if (input.IsNewButtonPress(Buttons.RightTrigger, screen.ControllingPlayer, out player))
            {
                if (library.Count > 0)
                {
                    char c = '0';
                    // Skip ahead artist letter

                    if (SongDataArray[selected].Artist.Length > 0)
                    {
                        c = SongDataArray[selected].Artist.ToLower()[0];
                    }
                    int newIndex;
                    for (newIndex = selected; newIndex < library.Count; ++newIndex)
                    {
                        loadAroundIndex(newIndex);
                        if (SongDataArray[newIndex].Artist.Length == 0)
                            continue;
                        if (SongDataArray[newIndex].Artist.ToLower()[0] != c)
                            break;
                    }
                    selected = Math.Min(newIndex, library.Count - 1);
                    index = selected;
                }
            }

            if (input.IsNewButtonPress(Buttons.LeftTrigger, screen.ControllingPlayer, out player))
            {
                if (library.Count > 0)
                {
                    char c = 'z';
                    // Skip back artist letter
                    if (SongDataArray[selected].Artist.Length > 0)
                    {
                        c = SongDataArray[selected].Artist.ToLower()[0];
                    }
                    int newIndex;
//.........这里部分代码省略.........
开发者ID:kmatzen,项目名称:EECS-494-Final-Project,代码行数:101,代码来源:SongSelectionBox.cs

示例10: HandleCursor

        public virtual void HandleCursor(InputState input)
        {
            PlayerIndex player;
            Vector2 position = Camera.ConvertScreenToWorld(input.Cursor);

            if ((input.IsNewButtonPress(Buttons.A, PlayerIndex.One, out player) ||
                    input.IsNewMouseButtonPress(MouseButtons.LeftButton)) &&
                _fixedMouseJoint == null)
            {
                Fixture savedFixture = World.TestPoint(position);
                if (savedFixture != null && savedFixture.UserData is SimpleAxiosGameObject && ((SimpleAxiosGameObject)(savedFixture.UserData)).AllowAutomaticMouseJoint)
                {
                    Body body = savedFixture.Body;
                    _fixedMouseJoint = new FixedMouseJoint(body, position);
                    _fixedMouseJoint.MaxForce = 1000.0f * body.Mass;
                    World.AddJoint(_fixedMouseJoint);
                    body.Awake = true;
                }
            }

            if ((input.IsNewButtonRelease(Buttons.A, ControllingPlayer.Value, out player) ||
                    input.IsNewMouseButtonRelease(MouseButtons.LeftButton)) &&
                _fixedMouseJoint != null)
            {
                World.RemoveJoint(_fixedMouseJoint);
                _fixedMouseJoint = null;
            }

            if (_fixedMouseJoint != null)
            {
                _fixedMouseJoint.WorldAnchorB = position;
            }
        }
开发者ID:nadams810,项目名称:axiosengine,代码行数:33,代码来源:PhysicsGameScreen.cs

示例11: HandleInput

        public override void HandleInput(GameTime gameTime, InputState input)
        {
            #if DEBUG
            // Control debug view
            PlayerIndex player;
            if (input.IsNewButtonPress(Buttons.Start, ControllingPlayer.Value, out player))
            {
                EnableOrDisableFlag(DebugViewFlags.Shape);
                EnableOrDisableFlag(DebugViewFlags.DebugPanel);
                EnableOrDisableFlag(DebugViewFlags.PerformanceGraph);
                EnableOrDisableFlag(DebugViewFlags.Joint);
                EnableOrDisableFlag(DebugViewFlags.ContactPoints);
                EnableOrDisableFlag(DebugViewFlags.ContactNormals);
                EnableOrDisableFlag(DebugViewFlags.Controllers);
            }

            if (input.IsNewKeyPress(Keys.F1, ControllingPlayer.Value, out player))
            {
                EnableOrDisableFlag(DebugViewFlags.Shape);
            }
            if (input.IsNewKeyPress(Keys.F2, ControllingPlayer.Value, out player))
            {
                EnableOrDisableFlag(DebugViewFlags.DebugPanel);
                EnableOrDisableFlag(DebugViewFlags.PerformanceGraph);
            }
            if (input.IsNewKeyPress(Keys.F3, ControllingPlayer.Value, out player))
            {
                EnableOrDisableFlag(DebugViewFlags.Joint);
            }
            if (input.IsNewKeyPress(Keys.F4, ControllingPlayer.Value, out player))
            {
                EnableOrDisableFlag(DebugViewFlags.ContactPoints);
                EnableOrDisableFlag(DebugViewFlags.ContactNormals);
            }
            if (input.IsNewKeyPress(Keys.F5, ControllingPlayer.Value, out player))
            {
                EnableOrDisableFlag(DebugViewFlags.PolygonPoints);
            }
            if (input.IsNewKeyPress(Keys.F6, ControllingPlayer.Value, out player))
            {
                EnableOrDisableFlag(DebugViewFlags.Controllers);
            }
            if (input.IsNewKeyPress(Keys.F7, ControllingPlayer.Value, out player))
            {
                EnableOrDisableFlag(DebugViewFlags.CenterOfMass);
            }
            if (input.IsNewKeyPress(Keys.F8, ControllingPlayer.Value, out player))
            {
                EnableOrDisableFlag(DebugViewFlags.AABB);
            }

            #endif

            if (_userAgent != null)
            {
                HandleUserAgent(input);
            }

            if (EnableCameraControl)
            {
                HandleCamera(input, gameTime);
            }

            if (HasCursor)
            {
                HandleCursor(input);
            }

            PlayerIndex i;
            if (input.IsNewButtonPress(Buttons.Back, PlayerIndex.One, out i) || input.IsNewKeyPress(Keys.Escape, PlayerIndex.One, out i))
            {
                //if (this.ScreenState == GameStateManagement.ScreenState.Active && this.TransitionPosition == 0 && this.TransitionAlpha == 1)
                //{ //Give the screens a chance to transition
                    CleanUp();
                    ExitScreen();

                //}
            }
            base.HandleInput(gameTime, input);
        }
开发者ID:nadams810,项目名称:axiosengine,代码行数:80,代码来源:PhysicsGameScreen.cs

示例12: HandleInput

        /// <summary>
        /// Lets the game respond to player input. Unlike the Update method,
        /// this will only be called when the gameplay screen is active.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            if (input == null)
                throw new ArgumentNullException("input");

            // Look up inputs for the active player profile.
            int playerIndex = (int)ControllingPlayer.Value;

            KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex];
            GamePadState gamePadState = input.CurrentGamePadStates[playerIndex];

            // if the user pressed the back button, we return to the main menu
            PlayerIndex player;
            if (input.IsNewButtonPress(Buttons.Back, ControllingPlayer, out player))
            {
                LoadingScreen.Load(ScreenManager, false, ControllingPlayer,
                                    new MenuBackgroundScreen("mainMenuBackground"),
                                    new MainMenuScreen());
            }
            else
            {
                // Otherwise move the player position.
                Vector2 movement = Vector2.Zero;

                if (keyboardState.IsKeyDown(Keys.Left))
                    movement.X--;

                if (keyboardState.IsKeyDown(Keys.Right))
                    movement.X++;

                if (keyboardState.IsKeyDown(Keys.Up))
                    movement.Y--;

                if (keyboardState.IsKeyDown(Keys.Down))
                    movement.Y++;

                Vector2 thumbstick = gamePadState.ThumbSticks.Left;

                movement.X += thumbstick.X;
                movement.Y -= thumbstick.Y;

                if (movement.Length() > 1)
                    movement.Normalize();

                playerPosition += movement * 2;
            }
        }
开发者ID:skakri09,项目名称:WinPhone-menuSystem,代码行数:51,代码来源:GameplayScreen.cs

示例13: HandleInput

        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public override void HandleInput(GameTime gameTime, InputState input)
        {
            // For input tests we pass in our ControllingPlayer, which may
            // either be null (to accept input from any player) or a specific index.
            // If we pass a null controlling player, the InputState helper returns to
            // us which player actually provided the input. We pass that through to
            // OnSelectEntry and OnCancel, so they can tell which player triggered them.

            #if WINDOWS || XBOX360
            PlayerIndex playerIndex;
            // Move to the previous menu entry?
            if (menuUp.Evaluate(input, ControllingPlayer, out playerIndex))
            {
                selectedEntry--;

                if (selectedEntry < 0)
                    selectedEntry = menuEntries.Count - 1;
            }

            // Move to the next menu entry?
            if (menuDown.Evaluate(input, ControllingPlayer, out playerIndex))
            {
                selectedEntry++;

                if (selectedEntry >= menuEntries.Count)
                    selectedEntry = 0;
            }

            if (menuSelect.Evaluate(input, ControllingPlayer, out playerIndex))
            {
                OnSelectEntry(selectedEntry, playerIndex);
            }
            else if (menuCancel.Evaluate(input, ControllingPlayer, out playerIndex))
            {
                OnCancel(playerIndex);
            }
            #endif

            #if WINDOWS_PHONE
            //selectedEntry = 1;

            PlayerIndex player;
            if (input.IsNewButtonPress(Buttons.Back, ControllingPlayer, out player))
            {
                OnCancel(player);
            }

            // look for any taps that occurred and select any entries that were tapped
            foreach (GestureSample gesture in input.Gestures)
            {
                //System.Diagnostics.Debugger.Break();
                if (gesture.GestureType == GestureType.Tap)
                {
                    // convert the position to a Point that we can test against a Rectangle
                    Point tapLocation = new Point((int)gesture.Position.X, (int)gesture.Position.Y);

                    // iterate the entries to see if any were tapped
                    for (int i = 0; i < menuEntries.Count; i++)
                    {
                        MenuEntry menuEntry = menuEntries[i];

                        if (GetMenuEntryHitBounds(menuEntry).Contains(tapLocation))
                        {
                            // select the entry. since gestures are only available on Windows Phone,
                            // we can safely pass PlayerIndex.One to all entries since there is only
                            // one player on Windows Phone.
                            OnSelectEntry(i, PlayerIndex.One);
                        }
                    }
                }
            }
            #endif
        }
开发者ID:nadams810,项目名称:axiosengine,代码行数:77,代码来源:MenuScreen.cs

示例14: HandleInput

        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            // Move to the previous menu entry?
            if (input.IsMenuUp(ControllingPlayer))
            {

                keyPos.Y--;
                if (keyPos.Y < 0)
                {
                    keyPos.Y = keys.Length - 1;
                }
            }

            // Move to the next menu entry?
            if (input.IsMenuDown(ControllingPlayer))
            {

                keyPos.Y++;
                if (keyPos.Y > keys.Length-1)
                {
                    keyPos.Y = 0;
                }
            }

             PlayerIndex playerIndex;

             if (input.IsMenuRight(ControllingPlayer))
             {
                 keyPos.X++;
                 if (keyPos.X > keys[(int)keyPos.Y].Length - 1)
                 {
                     keyPos.X = 0;
                 }
             }

             if (input.IsMenuLeft(ControllingPlayer))
             {
                 keyPos.X--;
                 if (keyPos.X < 0)
                 {
                     keyPos.X = keys[(int)keyPos.Y].Length - 1;
                 }
             }

            // Move to the next menu entry?
               //          public bool IsNewButtonPress(Buttons button, PlayerIndex? controllingPlayer,
             //                                            out PlayerIndex playerIndex)
            if ( input.IsNewButtonPress(Buttons.Y,ControllingPlayer, out playerIndex) )
            {
                playerNameChars[selectedEntry] = ' ';
                selectedEntry = Math.Min(selectedEntry + 1, numNameChars - 1);

                playerNameMenuEntry.Text = (new string(playerNameChars, 0, playerNameChars.Length));
            }

            // Accept or cancel the menu? We pass in our ControllingPlayer, which may
            // either be null (to accept input from any player) or a specific index.
            // If we pass a null controlling player, the InputState helper returns to
            // us which player actually provided the input. We pass that through to
            // OnSelectEntry and OnCancel, so they can tell which player triggered them.

            if (input.IsNewButtonPress(Buttons.A, ControllingPlayer, out playerIndex) )
            {
                OnSelectEntry(selectedEntry, playerIndex);
            }
            else if (input.IsNewButtonPress(Buttons.B, ControllingPlayer, out playerIndex) ||
                input.IsNewButtonPress(Buttons.X, ControllingPlayer, out playerIndex)
                )
            {
                OnCancel(playerIndex);
            }
            else if (input.IsNewButtonPress(Buttons.Start, ControllingPlayer, out playerIndex))
            {
                CompleteEntry();
            }
        }
开发者ID:kmatzen,项目名称:EECS-494-Final-Project,代码行数:80,代码来源:NameEntryScreen.cs

示例15: HandleInput

        /// <summary>
        /// Allows the screen to handle user input. Unlike Update, this method
        /// is only called when the screen is active, and not when some other
        /// screen has taken the focus.
        /// </summary>
        public virtual void HandleInput(InputState input)
        {
            PlayerIndex pindex;

            if (input.IsNewButtonPress(Buttons.Back, PlayerIndex.One, out pindex))
            {
                //SEND A BACK MESSAGE
                OnBackButton();
            }
        }
开发者ID:agentcox,项目名称:NodeHackEX-xna,代码行数:15,代码来源:GameScreen.cs


注:本文中的GameStateManagement.InputState.IsNewButtonPress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。