Exemple #1
0
        // Move the camera's position based on input
        public void HandleInput(InputState inputState, PlayerIndex?controllingPlayer)
        {
            Vector2 cameraMovement = Vector2.Zero;

            if (inputState.IsScrollLeft(controllingPlayer))
            {
                cameraMovement.X = -1;
            }
            else if (inputState.IsScrollRight(controllingPlayer))
            {
                cameraMovement.X = 1;
            }
            if (inputState.IsScrollUp(controllingPlayer))
            {
                cameraMovement.Y = -1;
            }
            else if (inputState.IsScrollDown(controllingPlayer))
            {
                cameraMovement.Y = 1;
            }
            if (inputState.IsZoomIn(controllingPlayer))
            {
                AdjustZoom(0.25f);
            }
            else if (inputState.IsZoomOut(controllingPlayer))
            {
                AdjustZoom(-0.25f);
            }

            // to match the thumbstick behavior, we need to normalize non-zero vectors in case the user
            // is pressing a diagonal direction.
            if (cameraMovement != Vector2.Zero)
            {
                cameraMovement.Normalize();
            }

            // scale our movement to move 25 pixels per second
            cameraMovement *= 25f;

            // move the camera
            MoveCamera(cameraMovement, true);
        }
Exemple #2
0
        // Move the camera's position based on input
        internal void HandleInput( InputState inputState, PlayerIndex? controllingPlayer )
        {
            Vector2 cameraMovement = Vector2.Zero;

             if ( inputState.IsScrollLeft( controllingPlayer ) )
             {
            cameraMovement.X = -1;
             }
             else if ( inputState.IsScrollRight( controllingPlayer ) )
             {
            cameraMovement.X = 1;
             }
             if ( inputState.IsScrollUp( controllingPlayer ) )
             {
            cameraMovement.Y = -1;
             }
             else if ( inputState.IsScrollDown( controllingPlayer ) )
             {
            cameraMovement.Y = 1;
             }
             if ( inputState.IsZoomIn( controllingPlayer ) )
             {
            AdjustZoom( 0.25f );
             }
             else if ( inputState.IsZoomOut( controllingPlayer ) )
             {
            AdjustZoom( -0.25f );
             }

             // to match the thumbstick behavior, we need to normalize non-zero vectors in case the user
             // is pressing a diagonal direction.
             if ( cameraMovement != Vector2.Zero )
             {
            cameraMovement.Normalize();
             }

             // scale our movement to move 25 pixels per second
             cameraMovement *= 25f;

             // move the camera
             MoveCamera( cameraMovement, true );
        }