[SOLVED] Tweenable Properties and OnComplete function?

Yeah, Action’s can be a little confusing when you’re new to them. They are very powerful when you get used to the idea though.

For example, there’s a few other ways you can write the same thing you have above.

  • You don’t need to store the Action in a variable. You can just pass the method directly into OnEnd like this:
_tweener.TweenTo(this, a => a.myPoint, new Vector2(endRect.Width, endRect.Height), duration: duration, delay: delay)
                .Easing(EasingFunctions.SineOut)
                .OnEnd(OnCompleteFunc);
  • Alternately, you can just inline the function directly using lambda syntax.
_tweener.TweenTo(this, a => a.myPoint, new Vector2(endRect.Width, endRect.Height), duration: duration, delay: delay)
                .Easing(EasingFunctions.SineOut)
                .OnEnd(tween => Console.Write("Tween Complete"));

or if you want to write more than one line of code:

_tweener.TweenTo(this, a => a.myPoint, new Vector2(endRect.Width, endRect.Height), duration: duration, delay: delay)
                .Easing(EasingFunctions.SineOut)
                .OnEnd(tween => 
                {
                    Console.Write("Tween Complete");
                    // do some other things here
                });

Once you’ve done it a few times you’ll wonder how you ever lived without them :wink:

1 Like