Gondwana Game Engine Development (master) - 2.6.1
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
SlideEffects.cs
1using System.Drawing;
5
6namespace Gondwana.Effects;
7
9public abstract class SlideEffect : DisplayEffect
10{
11 private readonly bool _isSlideIn;
12 private PointF _originalFactor;
13 private PointF _originalPixels;
14 private PointF _startFactor;
15 private PointF _targetFactor;
16
24 private protected SlideEffect(
25 EffectDirection direction,
26 float durationSeconds,
27 EasingKind easing,
28 bool isSlideIn)
29 : base(durationSeconds, easing)
30 {
31 if (direction == EffectDirection.None)
32 throw new ArgumentOutOfRangeException(nameof(direction));
33
34 Direction = direction;
35 _isSlideIn = isSlideIn;
36 }
37
39 public EffectDirection Direction { get; }
40
41 internal override EffectChannel Channel => EffectChannel.Transform;
42
43 internal override bool SupportsTarget(object target) =>
44 target is View or SceneLayer;
45
47 private protected override void OnStarting()
48 {
49 _originalFactor = EffectTargetAccess.GetOffsetFactor(Target);
50 _originalPixels = EffectTargetAccess.GetOffsetPixels(Target);
51
52 PointF travel = GetTravelFactor(Direction);
53
54 if (_isSlideIn)
55 {
56 _startFactor = IsNearlyZero(_originalFactor)
57 ? new PointF(-travel.X, -travel.Y)
58 : _originalFactor;
59
60 _targetFactor = PointF.Empty;
61 }
62 else
63 {
64 _startFactor = _originalFactor;
65 _targetFactor = travel;
66 }
67
68 EffectTargetAccess.SetTransform(
69 Target,
70 _startFactor,
71 _originalPixels);
72 }
73
75 private protected override void ApplyProgress(float progress)
76 {
77 var factor = new PointF(
78 _startFactor.X + (_targetFactor.X - _startFactor.X) * progress,
79 _startFactor.Y + (_targetFactor.Y - _startFactor.Y) * progress);
80
81 var pixels = new PointF(
82 _originalPixels.X * (1f - progress),
83 _originalPixels.Y * (1f - progress));
84
85 EffectTargetAccess.SetTransform(Target, factor, pixels);
86 }
87
89 private protected override void RestoreOriginalState() =>
90 EffectTargetAccess.SetTransform(Target, _originalFactor, _originalPixels);
91
92 private static bool IsNearlyZero(PointF value) =>
93 Math.Abs(value.X) < 0.0001f && Math.Abs(value.Y) < 0.0001f;
94
95 private static PointF GetTravelFactor(EffectDirection direction) => direction switch
96 {
97 EffectDirection.FromLeftToRight => new PointF(1f, 0f),
98 EffectDirection.FromRightToLeft => new PointF(-1f, 0f),
99 EffectDirection.FromTopToBottom => new PointF(0f, 1f),
100 EffectDirection.FromBottomToTop => new PointF(0f, -1f),
101 EffectDirection.FromTopLeftToBottomRight => new PointF(1f, 1f),
102 EffectDirection.FromTopRightToBottomLeft => new PointF(-1f, 1f),
103 EffectDirection.FromBottomLeftToTopRight => new PointF(1f, -1f),
104 EffectDirection.FromBottomRightToTopLeft => new PointF(-1f, -1f),
105 _ => throw new ArgumentOutOfRangeException(nameof(direction))
106 };
107}
108
110public sealed class SlideInEffect : SlideEffect
111{
117 EffectDirection direction,
118 float durationSeconds,
119 EasingKind easing = EasingKind.EaseOutCubic)
120 : base(direction, durationSeconds, easing, isSlideIn: true)
121 {
122 }
123}
124
126public sealed class SlideOutEffect : SlideEffect
127{
133 EffectDirection direction,
134 float durationSeconds,
135 EasingKind easing = EasingKind.EaseInCubic)
136 : base(direction, durationSeconds, easing, isSlideIn: false)
137 {
138 }
139}
DisplayEffect(float durationSeconds, EasingKind easing=EasingKind.Linear)
Initializes a new instance of the DisplayEffect class.
override void RestoreOriginalState()
EffectDirection Direction
Gets the direction in which the target travels.
override void OnStarting()
Captures or prepares target state before the effect starts.
override void ApplyProgress(float progress)
SlideEffect(EffectDirection direction, float durationSeconds, EasingKind easing, bool isSlideIn)
Initializes a new instance of the SlideEffect class.
SlideInEffect(EffectDirection direction, float durationSeconds, EasingKind easing=EasingKind.EaseOutCubic)
Creates a slide-in effect.
SlideOutEffect(EffectDirection direction, float durationSeconds, EasingKind easing=EasingKind.EaseInCubic)
Creates a slide-out effect.
Represents a rendered view of a scene, combining a camera position with a viewport configuration to c...
Definition View.cs:14
Represents a single layer within a Scene, containing a grid of tiles and supporting various coordinat...
Definition SceneLayer.cs:40
EffectDirection
Specifies the direction in which a directional display effect travels.
@ FromTopLeftToBottomRight
The effect travels from the upper-left corner toward the lower-right corner.
@ FromBottomLeftToTopRight
The effect travels from the lower-left corner toward the upper-right corner.
@ FromTopRightToBottomLeft
The effect travels from the upper-right corner toward the lower-left corner.
@ FromLeftToRight
The effect travels from the left edge toward the right edge.
@ FromBottomRightToTopLeft
The effect travels from the lower-right corner toward the upper-left corner.
@ FromRightToLeft
The effect travels from the right edge toward the left edge.
@ FromTopToBottom
The effect travels from the top edge toward the bottom edge.
@ FromBottomToTop
The effect travels from the bottom edge toward the top edge.
EasingKind
Enumeration of all supported easing functions for animation and movement interpolation....
Definition EasingKind.cs:9