feat: added engine member tween extensions
This commit is contained in:
@@ -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;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user