public Camera() { position = Vector2.Zero; zoom = 1.0f; transformMatrixDirty = true; motionState = CameraMotionState.Fixed; }
public Camera() { position = Vector2.Zero; zoom = 1.0f; transformMatrixDirty = true; motionState = CameraMotionState.Fixed; }
/// <summary> /// Pans the camera to a specified point in the world with a given duration. /// </summary> /// <param name="target">The target point in world space.</param> /// <param name="duration">How long the pan should take.</param> public void PanTo(Vector2 target, TimeSpan duration) { panOrigin = Position; panTarget = target; panDuration = duration; panTimeLeft = duration; motionState = CameraMotionState.Panning; }
/// <summary> /// Moves the camera immediately to the end of the current pan. /// </summary> public void CancelPan() { if (motionState == CameraMotionState.Panning) { Position = panTarget; motionState = CameraMotionState.Fixed; if (PanCompleted != null) { PanCompleted(); } } }
public void Update(GameTime gameTime) { // Update panning motion if (motionState == CameraMotionState.Panning) { panTimeLeft -= gameTime.ElapsedGameTime; if (panTimeLeft < TimeSpan.Zero) { panTimeLeft = TimeSpan.Zero; motionState = CameraMotionState.Fixed; Position = panTarget; if (PanCompleted != null) { PanCompleted(); } } else { double panPercentage = (panDuration.TotalMilliseconds - panTimeLeft.TotalMilliseconds) / panDuration.TotalMilliseconds; Position = Vector2.SmoothStep(panOrigin, panTarget, (float)panPercentage); } } }
/// <summary> /// Moves the camera immediately to the end of the current pan. /// </summary> public void CancelPan() { if (motionState == CameraMotionState.Panning) { Position = panTarget; motionState = CameraMotionState.Fixed; if (PanCompleted != null) { PanCompleted(); } } }
public void Update(GameTime gameTime) { // Update panning motion if (motionState == CameraMotionState.Panning) { panTimeLeft -= gameTime.ElapsedGameTime; if (panTimeLeft < TimeSpan.Zero) { panTimeLeft = TimeSpan.Zero; motionState = CameraMotionState.Fixed; Position = panTarget; if (PanCompleted != null) { PanCompleted(); } } else { double panPercentage = (panDuration.TotalMilliseconds - panTimeLeft.TotalMilliseconds) / panDuration.TotalMilliseconds; Position = Vector2.SmoothStep(panOrigin, panTarget, (float)panPercentage); } } }
/// <summary> /// Pans the camera to a specified point in the world with a given duration. /// </summary> /// <param name="target">The target point in world space.</param> /// <param name="duration">How long the pan should take.</param> public void PanTo(Vector2 target, TimeSpan duration) { panOrigin = Position; panTarget = target; panDuration = duration; panTimeLeft = duration; motionState = CameraMotionState.Panning; }