diff --git a/Engines/FlatRedBallXNA/FlatRedBall/Entities/CameraControllingEntity.cs b/Engines/FlatRedBallXNA/FlatRedBall/Entities/CameraControllingEntity.cs index d1a3c39c9..c0bb06a79 100644 --- a/Engines/FlatRedBallXNA/FlatRedBall/Entities/CameraControllingEntity.cs +++ b/Engines/FlatRedBallXNA/FlatRedBall/Entities/CameraControllingEntity.cs @@ -66,7 +66,14 @@ public PositionedObject Target { set { - if (Targets == null) + if (Targets == null || + // This is a little inefficient but the reason we need this is a user + // may use Targets initially and then switch to using a single Target. + // If Targets are used, the user may assign the Targets to a list that is + // not compatible with the assigned value. For example, Targets could be assigned + // to a List, but then the Target is set to a Player. This would result in an + // invalid cast operation when the Player is added to the List. + Targets is PositionedObjectList == false) { Targets = new PositionedObjectList(); } @@ -133,14 +140,14 @@ public bool LerpSmooth /// then the velocity of the camera will be 20*5 = 100. /// If TargetApproachStyle is ConstantSpeed, this is the speed of the camera in pixels per second. regardless of the distance to the target. /// - [Obsolete("Use ApproachCoefficient instead, since this value is confusingly named.")] + [Obsolete("Use TargetApproachCoefficient instead, since this value is confusingly named.")] public float LerpCoefficient { - get => ApproachCoefficient; - set => ApproachCoefficient = value; + get => TargetApproachCoefficient; + set => TargetApproachCoefficient = value; } - public float ApproachCoefficient { get; set; } = 5; + public float TargetApproachCoefficient { get; set; } = 5; /// /// Whether to snap the camera position to the screen pixel. This value can be used to prevent half-pixels from being drawn. @@ -539,11 +546,11 @@ public void ApplyTarget(Vector2 target, TargetApproachStyle approachStyleX, Targ switch (approachStyleX) { case TargetApproachStyle.Smooth: - effectiveThis.Velocity.X = (target.X - effectiveThis.Position.X) * ApproachCoefficient; + effectiveThis.Velocity.X = (target.X - effectiveThis.Position.X) * TargetApproachCoefficient; break; case TargetApproachStyle.ConstantSpeed: // todo - need to have a test here to see if we're within a range so we don't overshoot/jitter - effectiveThis.Velocity.X = System.Math.Sign(target.X - effectiveThis.Position.X) * ApproachCoefficient; + effectiveThis.Velocity.X = System.Math.Sign(target.X - effectiveThis.Position.X) * TargetApproachCoefficient; break; case TargetApproachStyle.Immediate: effectiveThis.Position.X = target.X; @@ -553,11 +560,11 @@ public void ApplyTarget(Vector2 target, TargetApproachStyle approachStyleX, Targ switch (approachStyleY) { case TargetApproachStyle.Smooth: - effectiveThis.Velocity.Y = (target.Y - effectiveThis.Position.Y) * ApproachCoefficient; + effectiveThis.Velocity.Y = (target.Y - effectiveThis.Position.Y) * TargetApproachCoefficient; break; case TargetApproachStyle.ConstantSpeed: // todo - need to have a test here to see if we're within a range so we don't overshoot/jitter - effectiveThis.Velocity.Y = System.Math.Sign(target.Y - effectiveThis.Position.Y) * ApproachCoefficient; + effectiveThis.Velocity.Y = System.Math.Sign(target.Y - effectiveThis.Position.Y) * TargetApproachCoefficient; break; case TargetApproachStyle.Immediate: effectiveThis.Position.Y = target.Y;