public override void HandleInput(InputState input) { PlayerIndex playerIndex; if (input.IsMenuSelect(ControllingPlayer, out playerIndex) || input.IsMenuCancel(ControllingPlayer, out playerIndex) || input.TapPosition.HasValue || input.MouseLeftClick) { LoadingScreen.Load(ScreenManager, false, null, new GameplayScreen(), new MainMenuScreen()); } base.HandleInput(input); }
/// <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"); if (startingTransition > 0f) return; // Look up inputs for the active player profile. int playerIndex = 0; KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex]; GamePadState gamePadState = input.CurrentGamePadStates[playerIndex]; PlayerIndex player; if (input.IsPauseGame(ControllingPlayer)) { PauseBackgroundScreen pauseBG = new PauseBackgroundScreen(); ScreenManager.AddScreen(pauseBG, ControllingPlayer); ScreenManager.AddScreen(new PauseMenuScreen(pauseBG), ControllingPlayer); } if(IsActive) { //Matrix mouseMatrix = Matrix.CreateTranslation(input.LastMouseState.X, input.LastMouseState.Y, 0) * -gameCamera.CameraMatrix;// Matrix.CreateTranslation(input.LastMouseState.X, input.LastMouseState.Y, 0); //mouseMatrix += Matrix.CreateTranslation(gameCamera.Position.X, gameCamera.Position.Y, 0); //mouseMatrix = mouseMatrix + Matrix.CreateRotationZ(-gameCamera.Rotation); //mouseMatrix -= Matrix.CreateTranslation(gameCamera.Width / 2, gameCamera.Height - 200, 0); //mousePos = Vector2.Transform(mousePos, gameCamera.CameraMatrix); //Quaternion camRot; //Vector3 dummy; //gameCamera.CameraMatrix.Decompose(out dummy, out camRot, out dummy); //mousePos += gameCamera.Position; //mousePos -= new Vector2(ScreenManager.GraphicsDevice.Viewport.Width / 2, ScreenManager.GraphicsDevice.Viewport.Height - 200); if (input.MouseDragging) { } #if WINRT || WINDOWS_PHONE // TouchCollection tc = TouchPanel.GetState(); foreach(TouchLocation tl in TouchPanel.GetState()) { if (tl.State == TouchLocationState.Pressed || tl.State == TouchLocationState.Moved) { mousePos = Vector2.Transform(tl.Position, Matrix.Invert(gameCamera.CameraMatrix)); gameHero.Fire(mousePos); } else gameHero.NotFiring(); } #else mousePos = new Vector2(input.LastMouseState.X, input.LastMouseState.Y); mousePos = Vector2.Transform(mousePos, Matrix.Invert(gameCamera.CameraMatrix)); #endif if (input.CurrentMouseState.LeftButton == ButtonState.Pressed) gameHero.Fire(mousePos); else gameHero.NotFiring(); if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.A)) gameHero.MoveBackward(); if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.D)) gameHero.MoveForward(); if (input.IsNewKeyPress(Keys.Space, null, out player)) gameHero.DoGravFlip(); if (Math.Abs(input.AccelerometerVect.Y) > 0.15f) { if (input.AccelerometerVect.Y>0) gameHero.MoveBackward(); if (input.AccelerometerVect.Y<0) gameHero.MoveForward(); } if (input.CurrentMouseState.Y < 150) { if(gameHUD.Alpha>0.2f) gameHUD.Alpha -= 0.02f; } else { if(gameHUD.Alpha<1f) gameHUD.Alpha += 0.02f; } } }
/// <summary> /// Responds to user input, accepting or cancelling the message box. /// </summary> public override void HandleInput(InputState input) { PlayerIndex playerIndex; // 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 our Accepted and // Cancelled events, so they can tell which player triggered them. if (input.IsMenuSelect(ControllingPlayer, out playerIndex)) { // Raise the accepted event, then exit the message box. if (Accepted != null) Accepted(this, new PlayerIndexEventArgs(playerIndex)); ExitScreen(); } else if (input.IsMenuCancel(ControllingPlayer, out playerIndex)) { // Raise the cancelled event, then exit the message box. if (Cancelled != null) Cancelled(this, new PlayerIndexEventArgs(playerIndex)); ExitScreen(); } 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); if (okRect.Contains(tapLocation)) { if (Accepted != null) Accepted(this, new PlayerIndexEventArgs(playerIndex)); ExitScreen(); } if (cancelRect.Contains(tapLocation)) { if (Cancelled != null) Cancelled(this, new PlayerIndexEventArgs(playerIndex)); ExitScreen(); } } } }
/// <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) { }
/// <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); } // 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 < 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); } } } } if (!ScreenManager.IsPhone) { Point mouseLocation = new Point(input.CurrentMouseState.X, input.CurrentMouseState.Y); for (int i = 0; i < menuEntries.Count; i++) { MenuEntry menuEntry = menuEntries[i]; if (GetMenuEntryHitBounds(menuEntry).Contains(mouseLocation)) { selectedEntry = i; // Mouse left click? if (input.CurrentMouseState.LeftButton == ButtonState.Released && input.LastMouseState.LeftButton == ButtonState.Pressed) { // 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); } } } } }