Example #1
0
        private static void OnAnimationCompleted(object sender, EventArgs e)
        {
            var component = sender as AnimationCameraComponent;

            component.AnimationCompleted -= OnAnimationCompleted;
            AnimationCompleted?.Invoke(sender, e);
        }
 /// <summary>
 /// Called if a child animation has been completed.
 /// </summary>
 public override void ChildAnimationCompleted()
 {
     if (IsAnimationCompleted)
     {
         AnimationCompleted.Trigger();
     }
 }
        protected override void Start()
        {
            if (AssociatedObject == null)
            {
                return;
            }

            DoubleAnimation aniX = new DoubleAnimation();

            aniX.To             = this.X;
            aniX.Duration       = this.Duration;
            aniX.FillBehavior   = this.FillBehavior;
            aniX.RepeatBehavior = this.RepeatBehavior;
            aniX.EasingFunction = this.EasingFunction;
            DoubleAnimation aniY = new DoubleAnimation();

            aniY.To             = this.Y;
            aniY.Duration       = this.Duration;
            aniY.FillBehavior   = this.FillBehavior;
            aniY.RepeatBehavior = this.RepeatBehavior;
            aniY.EasingFunction = this.EasingFunction;
            aniY.Completed     += (s, e) => { AnimationCompleted?.Execute(null); };
            (AssociatedObject as TranslateTransform).BeginAnimation(TranslateTransform.XProperty, aniX);
            (AssociatedObject as TranslateTransform).BeginAnimation(TranslateTransform.YProperty, aniY);
        }
 public AnimationWrapper(string name, Func <AnimationTimeline> animationInitializer,
                         DependencyProperty targetProperty,
                         AnimationCompleted onCompleted)
 {
     Name = name;
     АnimationInitializer = animationInitializer;
     TargetProperty       = targetProperty;
     OnCompleted          = onCompleted;
 }
        private static void AnimatorAnimationCompleted(object sender, AnimationCompletedEventArgs e)
        {
#if WPF
            var element = e.Source as Image;
            element?.RaiseEvent(e);
#elif WINRT || SILVERLIGHT
            AnimationCompleted?.Invoke(e.Source, e);
#endif
        }
Example #6
0
        /// <summary>
        /// Called when animation completed.
        /// </summary>
        void _viewFieldAnimator_Completed(ViewFieldAnimator viewFieldAnimator)
        {
            AnimationCompleted.Trigger();

            // notify parent
            if (LayoutParent is ViewAnimation)
            {
                (LayoutParent as ViewAnimation).ChildAnimationCompleted();
            }
        }
Example #7
0
                private void Da_AnimationCompleted(object sender, ClearUC.Utils.AnimationHelper.AnimationEventArgs e)
                {
                    switch (V)
                    {
                    case Visibility.Hidden:
                        E.Visibility = Visibility.Hidden;
                        break;
                    }

                    AnimationCompleted?.Invoke(this, new EventArgs());
                }
 private void NotifyPictureForm_FormClosing(object?sender, FormClosingEventArgs e)
 {
     if (!isCompleted && e.CloseReason == CloseReason.UserClosing)
     {
         e.Cancel = true;
     }
     else
     {
         AnimationCompleted?.Invoke(this, EventArgs.Empty);
     }
 }
Example #9
0
        public void StartEntranceEffect()
        {
            ContainerVisual container  = (ContainerVisual)ElementCompositionPreview.GetElementChildVisual(BasePage);
            Compositor      compositor = container.Compositor;

            // 设置缩放和动画
            const float               ScaleFactor = 20f;
            TimeSpan                  duration    = TimeSpan.FromMilliseconds(1200);
            LinearEasingFunction      linearEase  = compositor.CreateLinearEasingFunction();
            CubicBezierEasingFunction easeInOut   = compositor.CreateCubicBezierEasingFunction(new Vector2(.38f, 0f), new Vector2(.45f, 1f));

            // 创建淡出动画
            ScalarKeyFrameAnimation fadeOutAnimation = compositor.CreateScalarKeyFrameAnimation();

            fadeOutAnimation.InsertKeyFrame(1, 0);
            fadeOutAnimation.Duration = duration;

            // Grid的动画
            Vector2KeyFrameAnimation scaleUpGridAnimation = compositor.CreateVector2KeyFrameAnimation();

            scaleUpGridAnimation.InsertKeyFrame(0.1f, new Vector2(1 / ScaleFactor, 1 / ScaleFactor));
            scaleUpGridAnimation.InsertKeyFrame(1, new Vector2(1, 1));
            scaleUpGridAnimation.Duration = duration;

            // 初始屏动画
            Vector2KeyFrameAnimation scaleUpSplashAnimation = compositor.CreateVector2KeyFrameAnimation();

            scaleUpSplashAnimation.InsertKeyFrame(0, new Vector2(1, 1));
            scaleUpSplashAnimation.InsertKeyFrame(1, new Vector2(ScaleFactor, ScaleFactor));
            scaleUpSplashAnimation.Duration = duration;

            // 设置Grid的中心缩放视觉
            Visual gridVisual = ElementCompositionPreview.GetElementVisual(UIToShow);

            gridVisual.Size        = UIToShow.ActualSize;
            gridVisual.CenterPoint = new Vector3(gridVisual.Size.X, gridVisual.Size.Y, 0) * .5f;

            // 创建一个视觉组,当改组所有视觉执行完后不再显示
            CompositionScopedBatch batch = compositor.CreateScopedBatch(CompositionBatchTypes.Animation);

            container.StartAnimation("Opacity", fadeOutAnimation);
            container.StartAnimation("Scale.XY", scaleUpSplashAnimation);
            gridVisual.StartAnimation("Scale.XY", scaleUpGridAnimation);

            batch.Completed += (s, a) =>
            {
                ElementCompositionPreview.SetElementChildVisual(BasePage, null);
                SurfaceLoader.Uninitialize();
                AnimationCompleted?.Invoke(this, null);
            };
            batch.End();
        }
Example #10
0
        public void StartEntranceEffect()
        {
            try
            {
                TimeSpan AnimationDuration = TimeSpan.FromMilliseconds(1000);

                ContainerVisual Container = (ContainerVisual)ElementCompositionPreview.GetElementChildVisual(BasePage);

                ScalarKeyFrameAnimation FadeOutAnimation = Container.Compositor.CreateScalarKeyFrameAnimation();
                FadeOutAnimation.InsertKeyFrame(1, 0);
                FadeOutAnimation.Duration = AnimationDuration;

                Vector2KeyFrameAnimation ScaleUIAnimation = Container.Compositor.CreateVector2KeyFrameAnimation();
                ScaleUIAnimation.InsertKeyFrame(0.1f, new Vector2(1 / ScaleFactor, 1 / ScaleFactor));
                ScaleUIAnimation.InsertKeyFrame(1, new Vector2(1, 1));
                ScaleUIAnimation.Duration = AnimationDuration;

                Vector2KeyFrameAnimation ScaleSplashAnimation = Container.Compositor.CreateVector2KeyFrameAnimation();
                ScaleSplashAnimation.InsertKeyFrame(0, new Vector2(1, 1));
                ScaleSplashAnimation.InsertKeyFrame(1, new Vector2(ScaleFactor, ScaleFactor));
                ScaleSplashAnimation.Duration = AnimationDuration;

                Visual UIVisual = ElementCompositionPreview.GetElementVisual(UIToShow);
                UIVisual.Size        = new Vector2((float)UIToShow.ActualWidth, (float)UIToShow.ActualHeight);
                UIVisual.CenterPoint = new Vector3(UIVisual.Size.X, UIVisual.Size.Y, 0) * 0.5f;


                CompositionScopedBatch BatchAnimation = Container.Compositor.CreateScopedBatch(CompositionBatchTypes.Animation);

                Container.StartAnimation("Opacity", FadeOutAnimation);
                Container.StartAnimation("Scale.XY", ScaleSplashAnimation);
                UIVisual.StartAnimation("Scale.XY", ScaleUIAnimation);

                BatchAnimation.Completed += (s, a) =>
                {
                    ElementCompositionPreview.SetElementChildVisual(BasePage, null);
                    SurfaceLoader.Uninitialize();
                    AnimationCompleted?.Invoke(this, null);
                };

                BatchAnimation.End();
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Error in StartEntranceEffect, message:{ex.Message}");
            }
        }
Example #11
0
        internal void Update(float frameTime)
        {
            if (_playingAnimations.Count == 0)
            {
                return;
            }

            // TODO: Get rid of this ToArray() allocation.
            foreach (var(key, playback) in _playingAnimations.ToArray())
            {
                var keep = UpdatePlayback(Owner, playback, frameTime);
                if (!keep)
                {
                    _playingAnimations.Remove(key);
                    AnimationCompleted?.Invoke(key);
                }
            }
        }
        protected override void Start()
        {
            if (AssociatedObject == null)
            {
                return;
            }

            DoubleAnimation ani = new DoubleAnimation();

            ani.To             = this.Angle;
            ani.Duration       = this.Duration;
            ani.FillBehavior   = this.FillBehavior;
            ani.RepeatBehavior = this.RepeatBehavior;
            ani.EasingFunction = this.EasingFunction;

            ani.Completed += (s, e) => { AnimationCompleted?.Execute(null); };
            (AssociatedObject as RotateTransform).BeginAnimation(RotateTransform.AngleProperty, ani);
        }
Example #13
0
        private void DoAnimation(CancellationToken token)
        {
            TimeSpan durationFromStart;

            while ((durationFromStart = (DateTime.UtcNow - _startTime).Duration()) < TotalDuration)
            {
                if (token.IsCancellationRequested)
                {
                    return;
                }
                Double completedPart = durationFromStart.TotalMilliseconds / TotalDuration.TotalMilliseconds;
                Animatable.SetAnimationValue(From.MovePoint(completedPart * _vector));
                token.WaitHandle.WaitOne(5);
            }
            Animatable.SetAnimationValue(To);
            if (!token.IsCancellationRequested)
            {
                new Task(() => AnimationCompleted?.Invoke()).Start();
            }
            State = EAnimatorState.Stopped;
        }
Example #14
0
        public void Draw(GameTime gameTime, SpriteBatch spriteBatch, Vector2 position, SpriteEffects spriteEffects, Color color)
        {
            if (Animation == null)
            {
                return;
            }

            // Process passing time.
            time += (float)gameTime.ElapsedGameTime.TotalSeconds;
            while (time > Animation.FrameTime)
            {
                time -= Animation.FrameTime;

                // Advance the frame index; looping or clamping as appropriate.
                if (Animation.IsLooping)
                {
                    frameIndex = (frameIndex + 1) % Animation.FrameCount;
                }
                else
                {
                    frameIndex = Math.Min(frameIndex + 1, Animation.FrameCount - 1);
                }
            }


            // Calculate the source rectangle of the current frame.
            //Rectangle source = new Rectangle(FrameIndex * Animation.Texture.Height, 0, Animation.Texture.Height, Animation.Texture.Height);
            Rectangle source = new Rectangle(FrameIndex * Animation.FrameWidth, 0, Animation.FrameWidth, Animation.Texture.Height);

            // Draw the current frame.
            spriteBatch.Draw(Animation.Texture, position, source, color, 0.0f, Origin, 1.0f, spriteEffects, 0.0f);

            if (!Animation.IsLooping && frameIndex >= Animation.FrameCount - 1)
            {
                if (AnimationCompleted != null)
                {
                    AnimationCompleted.Invoke(this, new EventArgs());
                }
            }
        }
Example #15
0
        protected override void Start()
        {
            if (Timelines == null || !Timelines.Any())
            {
                return;
            }
            Storyboard sb = new Storyboard();

            sb.RepeatBehavior = this.RepeatBehavior;
            sb.FillBehavior   = this.FillBehavior;
            sb.Completed     += (s, e) =>
            {
                AnimationCompleted?.Execute(null);
            };
            foreach (var item in Timelines)
            {
                if (Storyboard.GetTargetName(item) == null && Storyboard.GetTarget(item) == null)
                {
                    Storyboard.SetTarget(item, this.AssociatedObject);
                }
                sb.Children.Add(item);
            }
            sb.Begin();
        }
Example #16
0
 protected virtual void OnAnimationCompleted(AnimationEventArgs e)
 {
     AnimationCompleted?.Invoke(this, e);
 }
Example #17
0
 private void Start()
 {
     _queue.QueueEmptied += () => AnimationCompleted?.Invoke();
 }
Example #18
0
 public void OnAnimationCompleted(float target)
 {
     AnimationCompleted?.Invoke(target);
 }
Example #19
0
 protected virtual void OnAnimationCompleted()
 {
     AnimationCompleted?.Invoke(this, new AnimationCompletedEventArgs(AnimationSource));
 }
		/// <summary>Calls the given delegate when the animation is over.</summary>
		public void OnDone(AnimationCompleted onComplete){
			OnComplete=onComplete;
		}
Example #21
0
 protected virtual void OnAnimationCompleted()
 {
     AnimationCompleted?.Invoke(this, EventArgs.Empty);
 }
Example #22
0
 /// <summary>Calls the given delegate when the animation is over.</summary>
 public void OnDone(AnimationCompleted onComplete)
 {
     OnComplete = onComplete;
 }
 private void OnCompleted()
 {
     AnimationCompleted?.Invoke(this, EventArgs.Empty);
 }
        public void MoveTo(Entity destinationEntity)
        {
            var scene = this.Owner.Scene;

            var cameraPoint = FindCameraPosition(this.Owner);

            List <Transform3D> path = calculatePath(this.Owner, cameraPoint, destinationEntity);

            var limitCameraBehavior = Owner.FindComponent <LimitCameraBehavior>();

            limitCameraBehavior.IsActive = false;

            IGameAction action = null;

            if (path.Count() > 1)
            {
                // rotation action
                IGameAction rotationAction = null;
                for (int i = 0; i < path.Count; i++)
                {
                    if (i == 0)
                    {
                        rotationAction = scene.CreateGameAction(
                            new RotateToShortest3DGameAction(
                                Owner,
                                path[i].Rotation,
                                TimeSpan.FromSeconds(TranslationDuration / path.Count),
                                EaseFunction.None,
                                false,
                                true));
                    }
                    else
                    {
                        rotationAction =
                            rotationAction.ContinueWith(
                                scene.CreateGameAction(
                                    new RotateToShortest3DGameAction(
                                        Owner,
                                        path[i].Rotation,
                                        TimeSpan.FromSeconds(TranslationDuration / path.Count),
                                        (i == path.Count - 1) ? EaseFunction.SineOutEase : EaseFunction.None,
                                        false,
                                        true)));
                    }
                }

                // init movement rotation
                var transform = this.Owner.FindComponent <Transform3D>();
                path.Insert(0, transform);
                CatmullRomSpline catmullRomSpline = new CatmullRomSpline(path.ToArray());

                action = scene.CreateParallelGameActions(
                    new FloatAnimationGameAction(
                        this.Owner,
                        0,
                        1,
                        TimeSpan.FromSeconds(TranslationDuration),
                        EaseFunction.SineInOutEase,
                        (lerp) =>
                {
                    transform.Position = catmullRomSpline.GetPosition(lerp);
                }),
                    rotationAction
                    )
                         .WaitAll();
            }
            else
            {
                action = scene.CreateParallelGameActions(
                    new MoveTo3DGameAction(
                        this.Owner,
                        path.Last().Position,
                        TimeSpan.FromSeconds(TranslationDuration),
                        EaseFunction.SineInOutEase),
                    new RotateToShortest3DGameAction(
                        this.Owner,
                        path.Last().Rotation,
                        TimeSpan.FromSeconds(TranslationDuration),
                        EaseFunction.SineOutEase,
                        false,
                        true))
                         .WaitAll();
            }

            if (action != null)
            {
                action.Run();
                action.Completed += (obj) =>
                {
                    limitCameraBehavior.OriginalRotation = path.Last().Rotation;
                    limitCameraBehavior.IsActive         = true;
                    var destinationLimitCameraBehavior = destinationEntity.FindComponent <LimitCameraBehavior>();
                    limitCameraBehavior.MaxPitch = destinationLimitCameraBehavior?.MaxPitch ?? LimitCameraBehavior.DefaultMaxPitch;
                    limitCameraBehavior.MaxYaw   = destinationLimitCameraBehavior?.MaxYaw ?? LimitCameraBehavior.DefaultMaxYaw;

                    // Invoke subscribed
                    AnimationCompleted?.Invoke(this, new EventArgs());
                };
            }
        }
Example #25
0
 /// <summary>Calls the given delegate when the animation is over.</summary>
 public void OnDone(AnimationCompleted onComplete)
 {
     addEventListener("finish", new EventListener <AnimationEvent>((AnimationEvent e) => onComplete(this)));
 }