A game framework written with osu! in mind.

Fix offset-based position transform not respecting previous transforms

+31 -2
+31 -2
osu.Framework/Graphics/TransformableExtensions.cs
··· 11 11 using JetBrains.Annotations; 12 12 using osu.Framework.Bindables; 13 13 using osu.Framework.Graphics.Effects; 14 + using osu.Framework.Utils; 14 15 15 16 namespace osu.Framework.Graphics 16 17 { ··· 666 667 public static TransformSequence<T> MoveToOffset<T, TEasing>(this T drawable, Vector2 offset, double duration, in TEasing easing) 667 668 where T : Drawable 668 669 where TEasing : IEasingFunction 669 - => drawable.MoveTo(((drawable.Transforms.LastOrDefault(t => t.TargetMember == nameof(drawable.Position)) as Transform<Vector2>)?.EndValue ?? drawable.Position) + offset, duration, 670 - easing); 670 + => drawable.TransformTo(drawable.PopulateTransform(new PositionOffsetTransform<TEasing>(offset), default, duration, easing)); 671 671 672 672 /// <summary> 673 673 /// Smoothly adjusts <see cref="IContainer.RelativeChildSize"/> over time. ··· 750 750 => drawable.TransformTo(drawable.PopulateTransform(new TransformBindable<TValue, TEasing, T>(bindable), newValue, duration, easing)); 751 751 752 752 #endregion 753 + 754 + private class PositionOffsetTransform<TEasing> : Transform<Vector2, TEasing, Drawable> 755 + where TEasing : IEasingFunction 756 + { 757 + private readonly Vector2 offset; 758 + 759 + public override string TargetMember => nameof(Drawable.Position); 760 + 761 + public PositionOffsetTransform(Vector2 offset) 762 + { 763 + this.offset = offset; 764 + } 765 + 766 + private Vector2 positionAt(double time) 767 + { 768 + if (time < StartTime) return StartValue; 769 + if (time >= EndTime) return EndValue; 770 + 771 + return Interpolation.ValueAt(time, StartValue, EndValue, StartTime, EndTime, Easing); 772 + } 773 + 774 + protected override void Apply(Drawable d, double time) => d.Position = positionAt(time); 775 + 776 + protected override void ReadIntoStartValue(Drawable d) 777 + { 778 + StartValue = d.Position; 779 + EndValue = d.Position + offset; 780 + } 781 + } 753 782 } 754 783 }