diff --git a/Engine.Systems/Tween/EngineExtensions/TweenShape2DExtensions.cs b/Engine.Systems/Tween/EngineExtensions/TweenShape2DExtensions.cs index e5d358b..00393dd 100644 --- a/Engine.Systems/Tween/EngineExtensions/TweenShape2DExtensions.cs +++ b/Engine.Systems/Tween/EngineExtensions/TweenShape2DExtensions.cs @@ -14,15 +14,21 @@ public static class TweenShape2DExtensions t => { shapeVertices.Clear(); - int count = Math.Lerp(initialVertices.Count, targetShape2D.Vertices.Count, t).RoundToInt(); - for (int i = 0; i < count; i++) + int maxCount = initialVertices.Count.Max(targetShape2D.Vertices.Count); + for (int i = 0; i < maxCount; i++) { - int initialIndex = i.Min(initialVertices.Count); - int targetIndex = i.Min(targetShape2D.Vertices.Count); + int initialIndex = (i * (initialVertices.Count / (float)maxCount)).RoundToInt(Math.RoundMode.Floor); + int targetIndex = (i * (targetShape2D.Vertices.Count / (float)maxCount)).RoundToInt(Math.RoundMode.Floor); shapeVertices.Add(targetShape2D.Vertices[targetIndex].Lerp(initialVertices[initialIndex], 1f - t)); } shape.Vertices = shapeVertices; } - ); + ).OnComplete(() => + { + shapeVertices.Clear(); + for (int i = 0; i < targetShape2D.Vertices.Count; i++) + shapeVertices.Add(targetShape2D.Vertices[i]); + shape.Vertices = shapeVertices; + }); } }