Skip to content

Commit

Permalink
Add special TweenTo.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gandifil committed Jan 22, 2024
1 parent f961461 commit a2e3aac
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/cs/MonoGame.Extended.Tweening/Tweener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using Microsoft.Xna.Framework;

namespace MonoGame.Extended.Tweening
{
Expand All @@ -26,6 +27,21 @@ public void Dispose()
public Tween<TMember> TweenTo<TTarget, TMember>(TTarget target, Expression<Func<TTarget, TMember>> expression, TMember toValue, float duration, float delay = 0f)
where TTarget : class
where TMember : struct
{
switch (toValue)
{
case Color toValueColor:
return (Tween<TMember>)(object)TweenTo<TTarget, Color, ColorTween>(target, expression as Expression<Func<TTarget, Color>>, toValueColor, duration, delay);
default:
return TweenTo<TTarget, TMember, LinearTween<TMember>>(target, expression, toValue, duration, delay);
}

}

public Tween<TMember> TweenTo<TTarget, TMember, TTween>(TTarget target, Expression<Func<TTarget, TMember>> expression, TMember toValue, float duration, float delay = 0f)
where TTarget : class
where TMember : struct
where TTween : Tween<TMember>
{
var memberExpression = (MemberExpression)expression.Body;
var memberInfo = memberExpression.Member;
Expand All @@ -35,7 +51,7 @@ public Tween<TMember> TweenTo<TTarget, TMember>(TTarget target, Expression<Func<
activeTween?.Cancel();

AllocationCount++;
var tween = new LinearTween<TMember>(target, duration, delay, member, toValue);
var tween = (TTween)Activator.CreateInstance(typeof(TTween), target, duration, delay, member, toValue);
_activeTweens.Add(tween);
return tween;
}
Expand Down

0 comments on commit a2e3aac

Please sign in to comment.