feat: added engine member tween extensions

This commit is contained in:
2025-05-03 22:23:52 +03:00
parent a93e55619c
commit be2295b92d
13 changed files with 218 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
using System.Collections.Generic;
using Syntriax.Engine.Core;
namespace Syntriax.Engine.Systems.Tween;
public static class TweenShape2DExtensions
{
public static ITween TweenShape2D(this Shape2D shape, ITweenManager tweenManager, float duration, Shape2D targetShape2D)
{
List<Vector2D> initialVertices = new(shape.Vertices);
List<Vector2D> shapeVertices = new(shape.Vertices);
return tweenManager.StartTween(duration,
t =>
{
shapeVertices.Clear();
int count = Math.Lerp(initialVertices.Count, targetShape2D.Vertices.Count, t).RoundToInt();
for (int i = 0; i < count; i++)
{
int initialIndex = i.Min(initialVertices.Count);
int targetIndex = i.Min(targetShape2D.Vertices.Count);
shapeVertices.Add(targetShape2D.Vertices[targetIndex].Lerp(initialVertices[initialIndex], 1f - t));
}
shape.Vertices = shapeVertices;
}
);
}
}