public static void UpdateMouse(GameTime gameTime, MouseState mState)
        {
            if (currentCamera == null)
            {
                currentCamera = Repository.GetSelectedCamera();
            }

            if (mState.LeftButton == ButtonState.Pressed)
            {
                // Taking into account the camera position since it is causing issues when the camera is moved.
                var currentMousePosition = mState.Position.ToVector2() + currentCamera.Transform.Position;
                var delta = Vector2.Zero;
                if (!LastMouseClick.Equals(Vector2.Zero))
                {
                    delta = currentMousePosition - LastMouseClick;
                }

                if (!Pressed)
                {
                    OnPress?.Invoke(new PointerEventDataArgs(currentMousePosition, delta));
                    Pressed = true;
                }

                LastMouseClick = currentMousePosition;

                if (delta != Vector2.Zero)
                {
                    OnDrag?.Invoke(new PointerEventDataArgs(currentMousePosition, delta));
                }

                if (LastMouseClick.Equals(Vector2.Zero))
                {
                    LastMouseClick = currentMousePosition;
                }
            }
            else if (Pressed)
            {
                OnRelease?.Invoke(new PointerEventDataArgs(LastMouseClick, Vector2.Zero));
                Pressed = false;

                LastMouseClick = Vector2.Zero;
            }
        }
Exemple #2
0
 public static void GenerateCamera(Viewport viewport)
 {
     var newCamera = new Camera2D(viewport);
     Repository.Cameras.Add(newCamera);
     Repository.SelectedCameraIndex = Repository.Cameras.Count - 1;
 }