diff --git a/Demos/EasingsDemo.cs b/Demos/EasingsDemo.cs
index 3600019..de0a324 100644
--- a/Demos/EasingsDemo.cs
+++ b/Demos/EasingsDemo.cs
@@ -17,6 +17,7 @@ namespace Demos {
.Select(f => (Easings.Easing) f.GetValue(null)).ToArray();
private Group group;
private int current;
+ private float progress;
public EasingsDemo(MlemGame game) : base(game) {
}
@@ -26,7 +27,10 @@ namespace Demos {
this.group = new Group(Anchor.TopCenter, Vector2.One) {SetWidthBasedOnChildren = true};
this.group.AddChild(new Button(Anchor.AutoCenter, new Vector2(30, 10), "Next") {
- OnPressed = e => this.current = (this.current + 1) % Easings.Length
+ OnPressed = e => {
+ this.current = (this.current + 1) % Easings.Length;
+ this.progress = 0;
+ }
});
this.group.AddChild(new Paragraph(Anchor.AutoCenter, 1, p => EasingFields[this.current].Name, true));
this.UiRoot.AddChild(this.group);
@@ -42,11 +46,20 @@ namespace Demos {
this.SpriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp);
var view = this.GraphicsDevice.Viewport;
- var easing = Easings[this.current].ScaleInput(0, view.Width).ScaleOutput(-view.Height / 3, view.Height / 3);
+
+ // graph the easing function
+ var graphEase = Easings[this.current].ScaleInput(0, view.Width).ScaleOutput(-view.Height / 3, view.Height / 3);
for (var x = 0; x < view.Width; x++) {
- var area = new RectangleF(x - 2, view.Height / 2 - easing(x) - 2, 4, 4);
+ var area = new RectangleF(x - 2, view.Height / 2 - graphEase(x) - 2, 4, 4);
this.SpriteBatch.Draw(this.SpriteBatch.GetBlankTexture(), area, Color.Green);
}
+
+ // draw a little dot to show what it would look like
+ this.progress = (this.progress + (float) time.ElapsedGameTime.TotalSeconds / 2) % 1;
+ var dotEase = Easings[this.current].AndReverse().ScaleOutput(0, view.Height / 4);
+ var pos = new RectangleF(view.Width / 2 - 4, view.Height - 20 - dotEase(this.progress), 8, 8);
+ this.SpriteBatch.Draw(this.SpriteBatch.GetBlankTexture(), pos, Color.Red);
+
this.SpriteBatch.End();
}
diff --git a/MLEM/Misc/Easings.cs b/MLEM/Misc/Easings.cs
index dad8e04..16261f3 100644
--- a/MLEM/Misc/Easings.cs
+++ b/MLEM/Misc/Easings.cs
@@ -100,6 +100,16 @@ namespace MLEM.Misc {
return p => easing(p) * (max - min) + min;
}
+ ///
+ /// Causes the easing functino to play fully, and then play fully in reverse, in the span between an input of 0 and 1.
+ /// In some places, this behavior is also called "auto-reversing".
+ ///
+ /// The easing function to play in reverse as well
+ /// An auto-reversing version of the easing function
+ public static Easing AndReverse(this Easing easing) {
+ return p => p <= 0.5F ? easing(p * 2) : easing(1 - (p - 0.5F) * 2);
+ }
+
///
/// A delegate method used by .
///