From feb2a05aa3e0683b62f7a306ab73df0def060dda Mon Sep 17 00:00:00 2001 From: Syntriax Date: Wed, 28 May 2025 16:55:48 +0300 Subject: [PATCH] feat: additive transform tweens added --- .../TweenTransform2DExtensions.cs | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/Engine.Systems/Tween/EngineExtensions/TweenTransform2DExtensions.cs b/Engine.Systems/Tween/EngineExtensions/TweenTransform2DExtensions.cs index 513b608..f4ca833 100644 --- a/Engine.Systems/Tween/EngineExtensions/TweenTransform2DExtensions.cs +++ b/Engine.Systems/Tween/EngineExtensions/TweenTransform2DExtensions.cs @@ -39,4 +39,69 @@ public static class TweenTransform2DExtensions float initialLocalRotation = transform2D.LocalRotation; return tweenManager.StartTween(duration, t => transform2D.LocalRotation = initialLocalRotation.Lerp(targetLocalRotation, t)); } + public static ITween TweenPositionAdditive(this ITransform2D transform2D, ITweenManager tweenManager, float duration, Vector2D additivePosition) + { + Vector2D progressedPosition = Vector2D.Zero; + return tweenManager.StartTween(duration, t => + { + Vector2D displacement = Vector2D.Zero.Lerp(additivePosition, t) - progressedPosition; + transform2D.Position += displacement; + progressedPosition += displacement; + }); + } + + public static ITween TweenScaleAdditive(this ITransform2D transform2D, ITweenManager tweenManager, float duration, Vector2D additiveScale) + { + Vector2D progressedScale = Vector2D.Zero; + return tweenManager.StartTween(duration, t => + { + Vector2D displacement = Vector2D.Zero.Lerp(additiveScale, t) - progressedScale; + transform2D.Scale += displacement; + progressedScale += displacement; + }); + } + + public static ITween TweenRotationAdditive(this ITransform2D transform2D, ITweenManager tweenManager, float duration, float additiveRotation) + { + float progressedRotation = 0f; + return tweenManager.StartTween(duration, t => + { + float displacement = 0f.Lerp(additiveRotation, t) - progressedRotation; + transform2D.Rotation += displacement; + progressedRotation += displacement; + }); + } + + public static ITween TweenLocalPositionAdditive(this ITransform2D transform2D, ITweenManager tweenManager, float duration, Vector2D additiveLocalPosition) + { + Vector2D progressedLocalPosition = Vector2D.Zero; + return tweenManager.StartTween(duration, t => + { + Vector2D displacement = Vector2D.Zero.Lerp(additiveLocalPosition, t) - progressedLocalPosition; + transform2D.LocalPosition += displacement; + progressedLocalPosition += displacement; + }); + } + + public static ITween TweenLocalScaleAdditive(this ITransform2D transform2D, ITweenManager tweenManager, float duration, Vector2D additiveLocalScale) + { + Vector2D progressedLocalScale = Vector2D.Zero; + return tweenManager.StartTween(duration, t => + { + Vector2D displacement = Vector2D.Zero.Lerp(additiveLocalScale, t) - progressedLocalScale; + transform2D.LocalScale += displacement; + progressedLocalScale += displacement; + }); + } + + public static ITween TweenLocalRotationAdditive(this ITransform2D transform2D, ITweenManager tweenManager, float duration, float additiveLocalRotation) + { + float progressedLocalRotation = 0f; + return tweenManager.StartTween(duration, t => + { + float displacement = 0f.Lerp(additiveLocalRotation, t) - progressedLocalRotation; + transform2D.LocalRotation += displacement; + progressedLocalRotation += displacement; + }); + } }