Ejemplo n.º 1
0
        /*protected override void Starting()
         * {
         *  base.Starting();
         *  Console.WriteLine("{0} Starting", GetType().Name);
         * }
         *
         * protected override void Completing()
         * {
         *  base.Completing();
         *  Console.WriteLine("{0} Completing", GetType().Name);
         * }*/
#endif
        #endregion

        #region Game Loop
        #endregion

        #region Animations
        public Task FloatAnimation(int duration, float startValue, float endValue, Action <float> valueStep, TweeningFunction easingFunction = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (duration <= 0)
            {
                throw new ArgumentOutOfRangeException("duration", "Duration must be greater than zero");
            }

            if (valueStep == null)
            {
                throw new ArgumentNullException("valueStep");
            }

            AnimationInfo info = new AnimationInfo
            {
                Completion      = new TaskCompletionSource <bool>(),
                Cancellation    = cancellationToken,
                CurrentDuration = 0,
                Duration        = duration,
                ValueStep       = valueStep,
                StartValue      = startValue,
                EndValue        = endValue,
                EasingFunction  = easingFunction,
            };

            if (cancellationToken != CancellationToken.None)
            {
                info.Cancellation.Register(() => info.Completion.TrySetCanceled());
            }

            if (_animations.Count == 0)
            {
                DrawContext.BeforeLoop += UpdateAnimations;
            }

            _animations.Add(info);
            info.NotifyValue();
            return(info.Completion.Task);
        }