private void MyOnGameStickUpdate(CCGameStickStatus left, CCGameStickStatus right, PlayerIndex player) { CCNode node = GetChildByTag(kTagTileMap); if (left.Magnitude > 0f) { // use the left stick to move the map CCPoint diff = left.Direction.InvertY * left.Magnitude * 10f; CCPoint currentPos = node.Position; node.Position = currentPos + diff; } if (right.Magnitude > 0f) { float scale = (1f - right.Direction.Y * right.Magnitude); node.Scale += scale; if (node.Scale < 1f) { node.Scale = 1f; } } }
protected override void OnGamePadStickUpdate(CCGameStickStatus leftStick, CCGameStickStatus rightStick, PlayerIndex player) { if (player == PlayerIndex.One) { _StickPull = leftStick.Magnitude; _StickDir = leftStick.Direction; // Do the rubber band CCPoint pt = CCPoint.Zero; pt.X = slingShotCenterPosition.X + _StickDir.X * _StickPull * maxStretchOfSlingShot; pt.Y = slingShotCenterPosition.Y + _StickDir.Y * _StickPull * maxStretchOfSlingShot; if (CockTheSlingshot(pt)) { _SlingshotIsCocked = true; } else { if (rightStick.Magnitude > 0f) { PanTheScreen((int)(rightStick.Magnitude * 25)); } } } else { // base.OnGamePadStickUpdate(leftStick, rightStick, player); } }
protected virtual void OnGamePadStickUpdate(CCGameStickStatus leftStick, CCGameStickStatus rightStick, Microsoft.Xna.Framework.PlayerIndex player) { }
private void ProcessGamePad(GamePadState gps, PlayerIndex player) { GamePadState lastState = new GamePadState(); if (m_PriorGamePadState.ContainsKey(player)) { lastState = m_PriorGamePadState[player]; // Notify listeners when the gamepad is connected. if ((lastState.IsConnected != gps.IsConnected) && GamePadConnectionUpdate != null) { GamePadConnectionUpdate(player, false); } // TODO: Check button pressed/released status for button tap events. } if (gps.IsConnected) { GamePadCapabilities caps = GamePad.GetCapabilities(player); if (GamePadButtonUpdate != null) { CCGamePadButtonStatus back = CCGamePadButtonStatus.NotApplicable; CCGamePadButtonStatus start = CCGamePadButtonStatus.NotApplicable; CCGamePadButtonStatus system = CCGamePadButtonStatus.NotApplicable; CCGamePadButtonStatus a = CCGamePadButtonStatus.NotApplicable; CCGamePadButtonStatus b = CCGamePadButtonStatus.NotApplicable; CCGamePadButtonStatus x = CCGamePadButtonStatus.NotApplicable; CCGamePadButtonStatus y = CCGamePadButtonStatus.NotApplicable; CCGamePadButtonStatus leftShoulder = CCGamePadButtonStatus.NotApplicable; CCGamePadButtonStatus rightShoulder = CCGamePadButtonStatus.NotApplicable; if (caps.HasBackButton) { back = (gps.Buttons.Back == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released); } if (caps.HasStartButton) { start = (gps.Buttons.Start == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released); } if (caps.HasBigButton) { system = (gps.Buttons.BigButton == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released); } if (caps.HasAButton) { a = (gps.Buttons.A == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released); } if (caps.HasBButton) { b = (gps.Buttons.B == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released); } if (caps.HasXButton) { x = (gps.Buttons.X == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released); } if (caps.HasYButton) { y = (gps.Buttons.Y == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released); } if (caps.HasLeftShoulderButton) { leftShoulder = (gps.Buttons.LeftShoulder == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released); } if (caps.HasRightShoulderButton) { rightShoulder = (gps.Buttons.RightShoulder == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released); } GamePadButtonUpdate(back, start, system, a, b, x, y, leftShoulder, rightShoulder, player); } // Process the game sticks if (GamePadStickUpdate != null && (caps.HasLeftXThumbStick || caps.HasLeftYThumbStick || caps.HasRightXThumbStick || caps.HasRightYThumbStick || caps.HasLeftStickButton || caps.HasRightStickButton)) { CCPoint vecLeft; if (caps.HasLeftXThumbStick || caps.HasLeftYThumbStick) { vecLeft = new CCPoint(gps.ThumbSticks.Left); vecLeft.Normalize(); } else { vecLeft = CCPoint.Zero; } CCPoint vecRight; if (caps.HasRightXThumbStick || caps.HasRightYThumbStick) { vecRight = new CCPoint(gps.ThumbSticks.Right); vecRight.Normalize(); } else { vecRight = CCPoint.Zero; } CCGameStickStatus left = new CCGameStickStatus(); left.Direction = vecLeft; left.Magnitude = ((caps.HasLeftXThumbStick || caps.HasLeftYThumbStick) ? gps.ThumbSticks.Left.Length() : 0f); left.IsDown = ((caps.HasLeftStickButton) ? gps.IsButtonDown(Buttons.LeftStick) : false); CCGameStickStatus right = new CCGameStickStatus(); right.Direction = vecRight; right.Magnitude = ((caps.HasRightXThumbStick || caps.HasRightYThumbStick) ? gps.ThumbSticks.Right.Length() : 0f); right.IsDown = ((caps.HasLeftStickButton) ? gps.IsButtonDown(Buttons.RightStick) : false); GamePadStickUpdate(left, right, player); } // Process the game triggers if (GamePadTriggerUpdate != null && (caps.HasLeftTrigger || caps.HasRightTrigger)) { GamePadTriggerUpdate(caps.HasLeftTrigger ? gps.Triggers.Left : 0f, caps.HasRightTrigger ? gps.Triggers.Right : 0f, player); } // Process the D-Pad if (GamePadDPadUpdate != null) { CCGamePadButtonStatus left = CCGamePadButtonStatus.NotApplicable; CCGamePadButtonStatus right = CCGamePadButtonStatus.NotApplicable; CCGamePadButtonStatus up = CCGamePadButtonStatus.NotApplicable; CCGamePadButtonStatus down = CCGamePadButtonStatus.NotApplicable; if (caps.HasDPadDownButton) { down = (gps.DPad.Down == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released); } if (caps.HasDPadUpButton) { up = (gps.DPad.Up == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released); } if (caps.HasDPadLeftButton) { left = (gps.DPad.Left == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released); } if (caps.HasDPadRightButton) { right = (gps.DPad.Right == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released); } GamePadDPadUpdate(left, up, right, down, player); } } m_PriorGamePadState[player] = gps; }