duck-tween icon indicating copy to clipboard operation
duck-tween copied to clipboard

Better ways to add repeated animations

Open kkjamie opened this issue 5 years ago • 0 comments

Problem

Quite often you want a sequence that contains a repeated portion of an animation. There is no decent way to do this, you either loop and create multiple instance of identical animations, or create one and add it multiple times. You can use linq, but then the .Add function only accepts params array, so requires a cast to an array,

Proposals

  1. A new overload AnimationCollection.Add(IEnumerable<TAnimation> animations) where TAnimation : AbstractAnimation This would allow us to use linq. so we can do don't need to do ToArray. the type parameters are present so we don't need .Cast<AbsrtactAnimation> - to surpress covariance warnings.

  2. Modify the original Add(params AbstractAnimation[] animations) to use type params for the same reason as above.

  3. A new overload Add(AbstractAnimation animation, int amount) so we can easily reuse the same instance multiple times over just using an integer

  4. ForEach(IEnumerable<T>, Func<T, AbstractAnimation> createAnimation) so we can map elements in an array to a corresponding animation eg: given a list of transforms myTransforms sequence.ForEach(myTransforms, t => t.Move(from, to, duration, easing));

kkjamie avatar Aug 09 '19 08:08 kkjamie