Gondwana Game Engine Development (master) - 2.7.0
Gondwana is a cross-platform 2.5D game and rendering engine written in C#/.NET 8. It provides fine-grained control over rendering, timing, and scene composition, with built-in support for parallax, z-ordering, pixel overhang, collision detection, and particle effects. Gondwana targets desktop and web platforms using SkiaSharp for graphics and pluggable audio backends for desktop and browser targets.
Loading...
Searching...
No Matches
Camera.cs
1using System.Drawing;
2using System.Numerics;
6
8
15public sealed class Camera
16{
17 private readonly Scene _scene;
18 private PointF _positionPx = new(0, 0);
19 private Func<PointF>? _followWorldPx;
20 private bool _hardFollow;
21 private SceneLayer? _followLayer;
22 private int _followAxis; // 0 = both, 1 = screen X, 2 = screen Y
23 private PointF _followAnchor = new(0.5f, 0.5f);
24 private SceneLayer? TopologyLayer => _followLayer ?? _scene.SceneLayers.FirstOrDefault(layer => layer.Visible);
25
26 // Explicit pan-to-target (camera upper-left) state.
27 // This is used by PanTo and is independent of the "follow" target.
28 private PointF? _panTargetUpperLeftPx;
29 private float _panLerpPerSecond;
30
36 public PointF PositionPx
37 {
38 get => _positionPx;
39 private set
40 {
41 if (_positionPx != value)
42 {
43 _positionPx = value;
44
45 if (_scene is not null)
46 _scene.FullRefreshNeeded = true;
47 }
48 }
49 }
50
58 public RectangleF WorldBoundsPx { get; set; } = RectangleF.Empty;
59
65 public Rectangle DeadZonePx { get; set; } = Rectangle.Empty;
66
72 public float FollowLerpPerSecond { get; set; } = 8f;
73
74 internal Camera(Scene scene) => _scene = scene ?? throw new ArgumentNullException(nameof(scene));
75
80 internal Func<SizeF> GetVisibleWorldSizePx { get; set; } = () => new SizeF(1280, 720);
81
82 #region Camera movement methods
83
92 public void SnapTo(PointF worldUpperLeftPx)
93 {
94 PositionPx = ClampToWorldBounds(worldUpperLeftPx);
95 }
96
105 public void CenterOn(PointF worldCenterPx)
106 {
107 var vis = GetVisibleWorldSizePx();
108
109 SnapTo(
110 new PointF(
111 worldCenterPx.X - vis.Width * 0.5f,
112 worldCenterPx.Y - vis.Height * 0.5f));
113 }
114
123 public void CenterOnGrid(SceneLayer layer, int col, int row)
124 {
125 // Anchor (top-left of tile)
126 var anchor = layer.GridToWorldPx(new PointF(col, row));
127 float tileCenterX = anchor.X + layer.TileWidth * 0.5f;
128 float tileCenterY = anchor.Y + layer.TileHeight * 0.5f;
129
130 var vis = GetVisibleWorldSizePx();
131
132 // Camera is top-left, so subtract half the visible size to center that point.
133 var camTopLeft = new PointF(
134 tileCenterX - vis.Width * 0.5f,
135 tileCenterY - vis.Height * 0.5f);
136
137 SnapTo(camTopLeft);
138 }
139
151 public void PanCenterTo(PointF worldCenterPx, float speed)
152 {
153 FollowLerpPerSecond = speed;
154
155 // For center-based pans, we treat the target as a "point of interest"
156 // and let the follow/dead-zone logic convert it to a camera UL.
157 Follow(() => worldCenterPx, hardFollow: false);
158 }
159
169 SceneLayer layer,
170 int col,
171 int row,
172 float speed)
173 {
174 // Compute world center of the tile and reuse PanCenterTo.
175 var anchor = layer.GridToWorldPx(new PointF(col, row));
176 float tileCenterX = anchor.X + layer.TileWidth * 0.5f;
177 float tileCenterY = anchor.Y + layer.TileHeight * 0.5f;
178
179 PanCenterTo(new PointF(tileCenterX, tileCenterY), speed);
180 }
181
194 public void PanTo(PointF worldTopLeftPx, float speed)
195 {
196 // Cancel any center-based follow when we take direct manual control.
197 _followAxis = 0;
198 _followLayer = null;
199 _followWorldPx = null;
200 _hardFollow = false;
201
202 if (speed <= 0f)
203 {
204 _panTargetUpperLeftPx = null;
205 SnapTo(worldTopLeftPx);
206 return;
207 }
208
209 _panLerpPerSecond = speed;
210 _panTargetUpperLeftPx = ClampToWorldBounds(worldTopLeftPx);
211 }
212
227 public void PanCenterToOnce(PointF worldCenterPx, float speed)
228 {
229 // Compute the desired camera upper-left such that worldCenterPx
230 // ends up in the middle of the visible region.
231 var vis = GetVisibleWorldSizePx();
232
233 var desiredUpperLeft = new PointF(
234 worldCenterPx.X - vis.Width * 0.5f,
235 worldCenterPx.Y - vis.Height * 0.5f);
236
237 // Delegate to the existing pan-to-upper-left logic (which also clamps).
238 PanTo(desiredUpperLeft, speed);
239 }
240
254 public void PanToOverDuration(PointF worldTopLeftPx, float durationSeconds)
255 {
256 if (durationSeconds <= 0f)
257 {
258 // Degenerate case — behave like SnapTo().
259 _panTargetUpperLeftPx = null;
260 SnapTo(worldTopLeftPx);
261 return;
262 }
263
264 // In an exponential smoothing system:
265 // pos(t) = target + (pos0 - target) * exp(-k * t)
266 //
267 // To reach ~99% of target position in T seconds:
268 // exp(-k*T) = 0.01 → k = -ln(0.01) / T
269 //
270 // This produces a visually nice, predictable time-to-arrive.
271 float k = -(float)Math.Log(0.01f) / durationSeconds;
272
273 // Cancel following and start a timed pan using your existing machinery.
274 _followAxis = 0;
275 _followLayer = null;
276 _followWorldPx = null;
277 _hardFollow = false;
278
279 _panLerpPerSecond = k;
280 _panTargetUpperLeftPx = ClampToWorldBounds(worldTopLeftPx);
281 }
282
296 public void PanCenterToOverDuration(PointF worldCenterPx, float durationSeconds)
297 {
298 // Compute the desired camera upper-left such that worldCenterPx
299 // ends up in the middle of the visible region.
300 var vis = GetVisibleWorldSizePx();
301
302 var desiredUpperLeft = new PointF(
303 worldCenterPx.X - vis.Width * 0.5f,
304 worldCenterPx.Y - vis.Height * 0.5f);
305
306 // Delegate to the duration-based UL pan logic.
307 PanToOverDuration(desiredUpperLeft, durationSeconds);
308 }
309
325 SceneLayer layer,
326 int col,
327 int row,
328 float durationSeconds)
329 {
330 if (layer is null)
331 throw new ArgumentNullException(nameof(layer));
332
333 // Same pattern as AnimateCenterOnGrid: get the tile's world-space anchor
334 // (top-left), then offset by half the tile size to get its visual center.
335 var anchor = layer.GridToWorldPx(new PointF(col, row));
336 float tileCenterX = anchor.X + layer.TileWidth * 0.5f;
337 float tileCenterY = anchor.Y + layer.TileHeight * 0.5f;
338
339 // Then pan so that tile center ends up at the center of the view
340 // over the requested duration.
341 PanCenterToOverDuration(new PointF(tileCenterX, tileCenterY), durationSeconds);
342 }
343
350 public void PanBy(PointF deltaPx)
351 {
352 SnapTo(
353 new PointF(
354 PositionPx.X + deltaPx.X,
355 PositionPx.Y + deltaPx.Y));
356 }
357
361 internal void CancelPan()
362 {
363 _panTargetUpperLeftPx = null;
364 _panLerpPerSecond = 0f;
365 }
366
382 public void Follow(Func<PointF> getWorldPixel, bool hardFollow = false)
383 {
384 FollowAt(getWorldPixel, new PointF(0.5f, 0.5f), hardFollow);
385 }
386
410 public void FollowAt(Func<PointF> getWorldPixel, PointF viewportAnchor, bool hardFollow = false)
411 {
412 ArgumentNullException.ThrowIfNull(getWorldPixel);
413 ValidateViewportAnchor(viewportAnchor, nameof(viewportAnchor));
414
415 _followAxis = 0;
416 _followLayer = null;
417 _followWorldPx = getWorldPixel;
418 _followAnchor = viewportAnchor;
419 _hardFollow = hardFollow;
420 }
421
430 public void FollowTo(PointF worldPointOfInterestPx)
431 {
432 // Freeze the value so the camera lerps toward a fixed point.
433 Follow(() => worldPointOfInterestPx);
434 }
435
444 public void FollowCentered(IMovableOnSceneLayer target, float speed = -1f, bool hard = false)
445 {
446 FollowAt(
447 target,
448 new PointF(0.5f, 0.5f),
449 speed,
450 hard);
451 }
452
468 public void FollowAt(
470 PointF viewportAnchor,
471 float speed = -1f,
472 bool hard = false)
473 {
474 ArgumentNullException.ThrowIfNull(target);
475 ValidateViewportAnchor(viewportAnchor, nameof(viewportAnchor));
476
477 if (speed > 0f)
478 FollowLerpPerSecond = speed;
479
480 FollowAt(
481 () =>
482 {
483 var layer = target.SceneLayer;
484 var pos = target.GetPosition();
485
486 return target.PositionSpace == MovementSpace.Grid
487 ? GetCenteredTile(layer, pos)
488 : new PointF(pos.X, pos.Y);
489 },
490 viewportAnchor,
491 hard);
492
493 _followLayer = target.SceneLayer;
494 }
495
503 public void FollowCenteredX(IMovableOnSceneLayer target, float speed = -1f, bool hard = false)
504 {
505 FollowAtX(
506 target,
507 0.5f,
508 speed,
509 hard);
510 }
511
527 public void FollowAtX(
529 float horizontalAnchor,
530 float speed = -1f,
531 bool hard = false)
532 {
533 ArgumentNullException.ThrowIfNull(target);
534 ValidateNormalizedAnchor(horizontalAnchor, nameof(horizontalAnchor));
535
536 if (speed > 0f)
537 FollowLerpPerSecond = speed;
538
539 FollowAt(
540 () =>
541 {
542 var layer = target.SceneLayer;
543 var pos = target.GetPosition();
544
545 float worldCenterX;
546
547 if (target.PositionSpace == MovementSpace.Grid)
548 {
549 var anchor = layer.GridToWorldPx(new PointF(pos.X, pos.Y));
550 worldCenterX = anchor.X + layer.TileWidth * 0.5f;
551 }
552 else
553 {
554 worldCenterX = pos.X;
555 }
556
557 var vis = GetVisibleWorldSizePx();
558
559 return new PointF(
560 worldCenterX,
561 PositionPx.Y + vis.Height * 0.5f);
562 },
563 new PointF(horizontalAnchor, 0.5f),
564 hard);
565
566 _followLayer = target.SceneLayer;
567 _followAxis = 1;
568 }
569
577 public void FollowCenteredY(IMovableOnSceneLayer target, float speed = -1f, bool hard = false)
578 {
579 FollowAtY(
580 target,
581 0.5f,
582 speed,
583 hard);
584 }
585
601 public void FollowAtY(
603 float verticalAnchor,
604 float speed = -1f,
605 bool hard = false)
606 {
607 ArgumentNullException.ThrowIfNull(target);
608 ValidateNormalizedAnchor(verticalAnchor, nameof(verticalAnchor));
609
610 if (speed > 0f)
611 FollowLerpPerSecond = speed;
612
613 FollowAt(
614 () =>
615 {
616 var layer = target.SceneLayer;
617 var pos = target.GetPosition();
618
619 float worldCenterY;
620
621 if (target.PositionSpace == MovementSpace.Grid)
622 {
623 var anchor = layer.GridToWorldPx(new PointF(pos.X, pos.Y));
624 worldCenterY = anchor.Y + layer.TileHeight * 0.5f;
625 }
626 else
627 {
628 worldCenterY = pos.Y;
629 }
630
631 var vis = GetVisibleWorldSizePx();
632
633 return new PointF(
634 PositionPx.X + vis.Width * 0.5f,
635 worldCenterY);
636 },
637 new PointF(0.5f, verticalAnchor),
638 hard);
639
640 _followLayer = target.SceneLayer;
641 _followAxis = 2;
642 }
643
648 public void ClearFollow()
649 {
650 _followAxis = 0;
651 _followLayer = null;
652 _followWorldPx = null;
653 _followAnchor = new PointF(0.5f, 0.5f);
654 _panTargetUpperLeftPx = null;
655 _hardFollow = false;
656 }
657
658 #endregion Camera movement methods
659
660 internal void Update(float dtSeconds)
661 {
662 // 1) Explicit pan-to-UL (PanTo) takes priority over center-follow.
663 if (_panTargetUpperLeftPx is { } panTarget)
664 {
665 var clamped = ClampToWorldBounds(panTarget);
666
667 if (_hardFollow || _panLerpPerSecond <= 0f)
668 {
669 PositionPx = clamped;
670 _panTargetUpperLeftPx = null;
671 }
672 else
673 {
674 float t = 1f - (float)Math.Exp(-_panLerpPerSecond * Math.Max(0f, dtSeconds));
675
676 var newPos = new PointF(
677 PositionPx.X + (clamped.X - PositionPx.X) * t,
678 PositionPx.Y + (clamped.Y - PositionPx.Y) * t);
679
680 PositionPx = newPos;
681
682 // Close enough → snap and finish.
683 if (Math.Abs(newPos.X - clamped.X) < 0.5f &&
684 Math.Abs(newPos.Y - clamped.Y) < 0.5f)
685 {
686 PositionPx = clamped;
687 _panTargetUpperLeftPx = null;
688 }
689 }
690
691 // If we're actively panning, don't also run center-follow this frame.
692 if (_panTargetUpperLeftPx is not null)
693 return;
694 }
695
696 // 2) Center-follow / dead-zone logic.
697 if (_followWorldPx is null)
698 return;
699
700 var target = _followWorldPx();
701
702 if (TopologyLayer is { } layer && (layer.WrapHorizontally || layer.WrapVertically))
703 {
704 var visible = GetVisibleWorldSizePx();
705
706 var followReference = new PointF(
707 PositionPx.X + visible.Width * _followAnchor.X,
708 PositionPx.Y + visible.Height * _followAnchor.Y);
709
710 var period = layer.GetPeriod();
711
712 if (_followAxis == 1)
713 {
714 target = NearestWrappedByAxis(
715 period,
716 target,
717 followReference,
718 followX: true);
719
720 target.Y = followReference.Y;
721 }
722 else if (_followAxis == 2)
723 {
724 target = NearestWrappedByAxis(
725 period,
726 target,
727 followReference,
728 followX: false);
729
730 target.X = followReference.X;
731 }
732 else
733 {
734 target = period.Nearest(target, followReference);
735 }
736 }
737
738 var desiredUL = DesiredUpperLeftToContainTarget(target);
739
740 if (_hardFollow || FollowLerpPerSecond <= 0f)
741 {
742 PositionPx = ClampToWorldBounds(desiredUL);
743 }
744 else
745 {
746 float t = 1f - (float)Math.Exp(-FollowLerpPerSecond * Math.Max(0f, dtSeconds));
747 var clamped = ClampToWorldBounds(desiredUL);
748
749 PositionPx = new PointF(
750 PositionPx.X + (clamped.X - PositionPx.X) * t,
751 PositionPx.Y + (clamped.Y - PositionPx.Y) * t);
752 }
753 }
754
755 #region private methods
756
757 private PointF DesiredUpperLeftToContainTarget(PointF targetWorldPx)
758 {
759 var vis = GetVisibleWorldSizePx();
760
761 if (DeadZonePx == Rectangle.Empty)
762 return new PointF(
763 targetWorldPx.X - vis.Width * _followAnchor.X,
764 targetWorldPx.Y - vis.Height * _followAnchor.Y);
765
766 var viewWorld = new RectangleF(
767 PositionPx.X,
768 PositionPx.Y,
769 vis.Width,
770 vis.Height);
771
772 var dzWorld = new RectangleF(
773 viewWorld.X + DeadZonePx.X,
774 viewWorld.Y + DeadZonePx.Y,
775 DeadZonePx.Width,
776 DeadZonePx.Height);
777
778 if (dzWorld.Contains(targetWorldPx))
779 return PositionPx;
780
781 float newX = PositionPx.X;
782 float newY = PositionPx.Y;
783
784 if (targetWorldPx.X < dzWorld.Left)
785 newX -= dzWorld.Left - targetWorldPx.X;
786
787 if (targetWorldPx.X > dzWorld.Right)
788 newX += targetWorldPx.X - dzWorld.Right;
789
790 if (targetWorldPx.Y < dzWorld.Top)
791 newY -= dzWorld.Top - targetWorldPx.Y;
792
793 if (targetWorldPx.Y > dzWorld.Bottom)
794 newY += targetWorldPx.Y - dzWorld.Bottom;
795
796 return new PointF(newX, newY);
797 }
798
799 private static PointF NearestWrappedByAxis(
800 LayerPeriod period,
801 PointF point,
802 PointF reference,
803 bool followX)
804 {
805 var delta = new PointF(reference.X - point.X, reference.Y - point.Y);
806 var coefficients = period.Coefficients(delta);
807 int baseColumn = (int)Math.Round(coefficients.X);
808 int baseRow = (int)Math.Round(coefficients.Y);
809
810 int minColumn = period.WrapColumns ? baseColumn - 4 : 0;
811 int maxColumn = period.WrapColumns ? baseColumn + 4 : 0;
812 int minRow = period.WrapRows ? baseRow - 4 : 0;
813 int maxRow = period.WrapRows ? baseRow + 4 : 0;
814
815 var best = period.Nearest(point, reference);
816 float bestAxisDistance = followX ? Math.Abs(best.X - reference.X) : Math.Abs(best.Y - reference.Y);
817
818 float bestDistanceSquared = (best.X - reference.X) * (best.X - reference.X) +
819 (best.Y - reference.Y) * (best.Y - reference.Y);
820
821 for (int c = minColumn; c <= maxColumn; c++)
822 for (int r = minRow; r <= maxRow; r++)
823 {
824 var offset = period.Offset(c, r);
825 var candidate = new PointF(point.X + offset.X, point.Y + offset.Y);
826 float axisDistance = followX ? Math.Abs(candidate.X - reference.X) : Math.Abs(candidate.Y - reference.Y);
827
828 float distanceSquared = (candidate.X - reference.X) * (candidate.X - reference.X) +
829 (candidate.Y - reference.Y) * (candidate.Y - reference.Y);
830
831 if (axisDistance < bestAxisDistance ||
832 (axisDistance == bestAxisDistance && distanceSquared < bestDistanceSquared))
833 {
834 best = candidate;
835 bestAxisDistance = axisDistance;
836 bestDistanceSquared = distanceSquared;
837 }
838 }
839
840 return best;
841 }
842
843 private PointF ClampToWorldBounds(PointF ul)
844 {
845 if (WorldBoundsPx == RectangleF.Empty)
846 return ul;
847
848 var vis = GetVisibleWorldSizePx();
849
850 if (TopologyLayer is { } layer && (layer.WrapHorizontally || layer.WrapVertically))
851 {
852 var period = layer.GetPeriod();
853 var position = period.Coefficients(ul);
854
855 PointF[] Corners(RectangleF rect) => new[]
856 {
857 period.Coefficients(new(rect.Left, rect.Top)), period.Coefficients(new(rect.Right, rect.Top)),
858 period.Coefficients(new(rect.Left, rect.Bottom)), period.Coefficients(new(rect.Right, rect.Bottom))
859 };
860
861 var bounds = Corners(WorldBoundsPx);
862
863 var viewport = Corners(
864 new(
865 0,
866 0,
867 vis.Width,
868 vis.Height));
869
870 float lowX = bounds.Min(p => p.X) - viewport.Min(p => p.X);
871 float lowY = bounds.Min(p => p.Y) - viewport.Min(p => p.Y);
872 float highX = Math.Max(lowX, bounds.Max(p => p.X) - viewport.Max(p => p.X));
873 float highY = Math.Max(lowY, bounds.Max(p => p.Y) - viewport.Max(p => p.Y));
874
875 return period.Offset(
876 layer.WrapHorizontally ? position.X : Math.Clamp(position.X, lowX, highX),
877 layer.WrapVertically ? position.Y : Math.Clamp(position.Y, lowY, highY));
878 }
879
880 float minX = WorldBoundsPx.Left;
881 float minY = WorldBoundsPx.Top;
882 float maxX = WorldBoundsPx.Right - vis.Width;
883 float maxY = WorldBoundsPx.Bottom - vis.Height;
884
885 if (maxX < minX)
886 maxX = minX;
887
888 if (maxY < minY)
889 maxY = minY;
890
891 return new PointF(
892 Math.Clamp(ul.X, minX, maxX),
893 Math.Clamp(ul.Y, minY, maxY));
894 }
895
896 private static void ValidateViewportAnchor(PointF viewportAnchor, string paramName)
897 {
898 ValidateNormalizedAnchor(viewportAnchor.X, paramName);
899 ValidateNormalizedAnchor(viewportAnchor.Y, paramName);
900 }
901
902 private static void ValidateNormalizedAnchor(float value, string paramName)
903 {
904 if (!float.IsFinite(value) || value < 0f || value > 1f)
905 throw new ArgumentOutOfRangeException(
906 paramName,
907 value,
908 "Camera follow anchors must be finite values from 0 through 1.");
909 }
910
918 private static PointF GetCenteredTile(SceneLayer layer, Vector2 gridPos)
919 {
920 var anchor = layer.GridToWorldPx(new PointF(gridPos.X, gridPos.Y));
921
922 return new PointF(
923 anchor.X + layer.TileWidth * 0.5f,
924 anchor.Y + layer.TileHeight * 0.5f);
925 }
926
927 #endregion private methods
928}
Represents a world-space camera for a Scene. The camera tracks a world-space upper-left position in p...
Definition Camera.cs:16
void PanCenterToOverDuration(PointF worldCenterPx, float durationSeconds)
Smoothly pans the camera so that the specified world-space point becomes the visual center of the vie...
Definition Camera.cs:296
void PanToGridOverDuration(SceneLayer layer, int col, int row, float durationSeconds)
Smoothly pans the camera so that the specified grid tile becomes the visual center of the view over a...
Definition Camera.cs:324
void FollowAtY(IMovableOnSceneLayer target, float verticalAnchor, float speed=-1f, bool hard=false)
Smoothly follows an IMovable target vertically while keeping its center at a normalized vertical posi...
Definition Camera.cs:601
Rectangle DeadZonePx
Size of the dead zone, in pixels, around the center of the view where the follow target is allowed to...
Definition Camera.cs:65
float FollowLerpPerSecond
Controls how quickly the camera moves toward its follow target when smooth follow is enabled....
Definition Camera.cs:72
void FollowCentered(IMovableOnSceneLayer target, float speed=-1f, bool hard=false)
Makes the camera follow an IMovable-on-SceneLayer so that the object stays centered in the view....
Definition Camera.cs:444
void SnapTo(PointF worldUpperLeftPx)
Instantly moves the camera to the specified world-space position, interpreted as the upper-left corne...
Definition Camera.cs:92
void AnimateCenterOnGrid(SceneLayer layer, int col, int row, float speed)
Smoothly pans the camera until the specified grid tile is centered in the view. Uses the given follow...
Definition Camera.cs:168
void FollowCenteredY(IMovableOnSceneLayer target, float speed=-1f, bool hard=false)
Smoothly follows an IMovable target, centering it vertically only. Horizontal camera position is left...
Definition Camera.cs:577
void Follow(Func< PointF > getWorldPixel, bool hardFollow=false)
Configures the camera to follow a dynamically supplied world-space target position....
Definition Camera.cs:382
void FollowAtX(IMovableOnSceneLayer target, float horizontalAnchor, float speed=-1f, bool hard=false)
Smoothly follows an IMovable target horizontally while keeping its center at a normalized horizontal ...
Definition Camera.cs:527
void PanCenterToOnce(PointF worldCenterPx, float speed)
Smoothly pans the camera so that the specified world-space point becomes the visual center of the vie...
Definition Camera.cs:227
PointF PositionPx
Gets or sets the camera's world-space position in pixels, interpreted as the upper-left corner of the...
Definition Camera.cs:37
void ClearFollow()
Clears any active follow or pan targets; the camera remains at its current position until moved again...
Definition Camera.cs:648
void CenterOnGrid(SceneLayer layer, int col, int row)
Instantly centers the camera on the specified tile in the given SceneLayer. The tile's visual center ...
Definition Camera.cs:123
void CenterOn(PointF worldCenterPx)
Instantly repositions the camera so that the given world-space point appears at the center of the vie...
Definition Camera.cs:105
void PanCenterTo(PointF worldCenterPx, float speed)
Smoothly pans the camera so that the given world-space point ends up at the center of the visible vie...
Definition Camera.cs:151
void FollowAt(Func< PointF > getWorldPixel, PointF viewportAnchor, bool hardFollow=false)
Configures the camera to follow a dynamically supplied world-space target while keeping that target a...
Definition Camera.cs:410
void FollowCenteredX(IMovableOnSceneLayer target, float speed=-1f, bool hard=false)
Smoothly follows an IMovable target, centering it horizontally only. Vertical camera position is left...
Definition Camera.cs:503
void PanToOverDuration(PointF worldTopLeftPx, float durationSeconds)
Smoothly pans the camera so that its upper-left pixel reaches the specified world-space target over a...
Definition Camera.cs:254
void FollowTo(PointF worldPointOfInterestPx)
Starts smooth camera movement toward a fixed world-space "point ofinterest" (typically a center point...
Definition Camera.cs:430
void FollowAt(IMovableOnSceneLayer target, PointF viewportAnchor, float speed=-1f, bool hard=false)
Makes the camera follow an IMovable-on-SceneLayer while keeping the object's center at a normalized p...
Definition Camera.cs:468
RectangleF WorldBoundsPx
World-space rectangle (in pixels) that the camera is allowed to move within. Clamping logic uses this...
Definition Camera.cs:58
void PanTo(PointF worldTopLeftPx, float speed)
Smoothly pans the camera toward a world-space top-left position for the view, using the given follow ...
Definition Camera.cs:194
void PanBy(PointF deltaPx)
Instantly pans the camera by the given offset in world-space pixels. This adds the offset to the curr...
Definition Camera.cs:350
Represents a single layer within a Scene, containing a grid of tiles and supporting various coordinat...
Definition SceneLayer.cs:40
int TileHeight
Gets or sets the height of each tile in this layer, measured in pixels.
PointF GridToWorldPx(PointF grid)
Converts a grid coordinate (col,row) into the projection-defined world-space pixel anchor for that ti...
int TileWidth
Gets or sets the width of each tile in this layer, measured in pixels.
Represents a game scene containing multiple layers of tiles, sprites, and game objects....
Definition Scene.cs:35
Implemented by grid-space IMovable objects that belong to a specific Scenes.SceneLayer.
SceneLayer SceneLayer
Gets the Scenes.SceneLayer that this movable object belongs to.
Vector2 GetPosition()
Get the current position in the mover's PositionSpace.
MovementSpace PositionSpace
Which unit system this mover uses for its position.
Definition IMovable.cs:14
@ Rectangle
Particles are spawned uniformly within a rectangular area. This is the default distribution.
MovementSpace
Specifies the coordinate system used for movement calculations and updates.
@ Grid
Movement is in a scene's grid/tile coordinate system.