Example #1
0
        /// <summary>
        /// 螺旋摘要关键帧变化
        /// </summary>
        /// <param name="keyFrameFrom"></param>
        /// <param name="keyFrameTo"></param>
        /// <param name="duration"></param>
        public static Storyboard KeyFrameInSpiralMove(KeyFrame keyFrameFrom, double duration, PathGeometry pathGeometry)
        {
            keyFrameFrom.Image.Margin = new Thickness(0);

            MatrixTransform ImageMatrixTransform = new MatrixTransform();

            keyFrameFrom.Image.RenderTransform = ImageMatrixTransform;
            NameScope.SetNameScope(keyFrameFrom.Image, new NameScope());
            keyFrameFrom.Image.RegisterName("ImageMatrixTransform", ImageMatrixTransform);

            MatrixAnimationUsingPath matrixAnimation = new MatrixAnimationUsingPath();

            matrixAnimation.PathGeometry = pathGeometry;
            matrixAnimation.Duration     = TimeSpan.FromSeconds(duration);
            //matrixAnimation.RepeatBehavior = RepeatBehavior.Forever;
            // matrixAnimation.DoesRotateWithTangent = true;
            Storyboard.SetTargetName(matrixAnimation, "ImageMatrixTransform");
            Storyboard.SetTargetProperty(matrixAnimation,
                                         new PropertyPath(MatrixTransform.MatrixProperty));

            // Create a Storyboard to contain and apply the animation.
            Storyboard pathAnimationStoryboard = new Storyboard();

            pathAnimationStoryboard.Children.Add(matrixAnimation);
            return(pathAnimationStoryboard);
        }
Example #2
0
        public void startAnimation(Car _animateObject, int animationTime, int delay)
        {
            Application.Current.Dispatcher.BeginInvoke(new Action(() =>
            {
                lock (lock1)
                {
                    NameScope.SetNameScope(mainWin, new NameScope());
                    MatrixTransform carTransform           = new MatrixTransform();
                    _animateObject._carImg.RenderTransform = carTransform;
                    mainWin.RegisterName("carTransform", carTransform);

                    PathGeometry animPath = new PathGeometry();
                    PathFigure pathFigure = new PathFigure();
                    pathFigure.StartPoint = _startPoint;
                    pathFigure.Segments.Add(new LineSegment(_endPoint, false));

                    animPath.Figures.Add(pathFigure);
                    animPath.Freeze();

                    MatrixAnimationUsingPath mAnim = new MatrixAnimationUsingPath();
                    mAnim.PathGeometry             = animPath;
                    mAnim.Duration = TimeSpan.FromSeconds(animationTime);

                    Storyboard.SetTargetName(mAnim, "carTransform");
                    Storyboard.SetTargetProperty(mAnim, new PropertyPath(MatrixTransform.MatrixProperty));

                    story.Children.Add(mAnim);
                    story.Begin(mainWin, true);
                }
            }));
        }
Example #3
0
        private void Test_Matrix()
        {
            Canvas.SetLeft(this.border1, -this.border1.ActualWidth / 2);
            Canvas.SetTop(this.border1, -this.border1.ActualHeight / 2);
            this.border1.RenderTransformOrigin = new Point(0.5, 0.5);

            MatrixTransform matrix = new MatrixTransform();

            this.border1.RenderTransform = matrix;

            NameScope.SetNameScope(this, new NameScope());
            this.RegisterName("matrix", matrix);

            MatrixAnimationUsingPath matrixAnimation = new MatrixAnimationUsingPath();

            matrixAnimation.PathGeometry          = this.path1.Data.GetFlattenedPathGeometry();
            matrixAnimation.Duration              = new Duration(TimeSpan.FromSeconds(2));
            matrixAnimation.RepeatBehavior        = RepeatBehavior.Forever;
            matrixAnimation.AutoReverse           = true;
            matrixAnimation.IsOffsetCumulative    = !matrixAnimation.AutoReverse;
            matrixAnimation.DoesRotateWithTangent = true;//旋转


            Storyboard story = new Storyboard();

            story.Children.Add(matrixAnimation);
            Storyboard.SetTargetName(matrixAnimation, "matrix");
            Storyboard.SetTargetProperty(matrixAnimation, new PropertyPath(MatrixTransform.MatrixProperty));
            story.Begin(this);
        }
Example #4
0
        public static void AddPointToStoryboard(Grid runPoint, Ellipse toEll, Storyboard sb, PathGeometry pathGeometry, double pointTime)
        {
            //double pointTime = l / m_Speed;//点运动所需的时间
            double particleTime = pointTime / 2;//轨迹呈现所需时间(跑的比点快两倍)

            #region 运动的点
            TransformGroup  tfg = new TransformGroup();
            MatrixTransform mtf = new MatrixTransform();
            tfg.Children.Add(mtf);
            TranslateTransform ttf = new TranslateTransform(-runPoint.Width / 2, -runPoint.Height / 2);//纠正最上角沿path运动到中心沿path运动
            tfg.Children.Add(ttf);
            runPoint.RenderTransform = tfg;

            MatrixAnimationUsingPath maup = new MatrixAnimationUsingPath
            {
                PathGeometry          = pathGeometry,
                Duration              = new Duration(TimeSpan.FromSeconds(pointTime)),
                RepeatBehavior        = RepeatBehavior.Forever,
                AutoReverse           = false,
                IsOffsetCumulative    = false,
                DoesRotateWithTangent = true
            };
            Storyboard.SetTarget(maup, runPoint);
            Storyboard.SetTargetProperty(maup, new PropertyPath("(Grid.RenderTransform).Children[0].(MatrixTransform.Matrix)"));
            sb.Children.Add(maup);
            #endregion

            #region 达到城市的圆

            var ellda = Animation1(particleTime);
            Storyboard.SetTarget(ellda, toEll);
            Storyboard.SetTargetProperty(ellda, new PropertyPath(Ellipse.OpacityProperty));
            sb.Children.Add(ellda);


            RadialGradientBrush rgBrush = new RadialGradientBrush();
            GradientStop        gStop0  = new GradientStop(Color.FromArgb(255, 0, 0, 0), 0);

            GradientStop gStopT = new GradientStop(Color.FromArgb(255, 0, 0, 0), 0);
            GradientStop gStop1 = new GradientStop(Color.FromArgb(255, 0, 0, 0), 1);
            rgBrush.GradientStops.Add(gStop0);
            rgBrush.GradientStops.Add(gStopT);
            rgBrush.GradientStops.Add(gStop1);
            toEll.OpacityMask = rgBrush;


            var ca = ColorAnimation(pointTime);
            Storyboard.SetTarget(ca, toEll);
            Storyboard.SetTargetProperty(ca, new PropertyPath("(Ellipse.OpacityMask).(GradientBrush.GradientStops)[1].(GradientStop.Color)"));
            sb.Children.Add(ca);


            var eda = Animation2(particleTime);
            Storyboard.SetTarget(eda, toEll);
            Storyboard.SetTargetProperty(eda, new PropertyPath("(Ellipse.OpacityMask).(GradientBrush.GradientStops)[1].(GradientStop.Offset)"));
            sb.Children.Add(eda);
            #endregion
        }
        MatrixAnimationUsingPath CreatematrixAnimationTransform(double startXOffset, double endXOffset)
        {
            MatrixAnimationUsingPath transformMatrix = new MatrixAnimationUsingPath();

            transformMatrix.PathGeometry = new PathGeometry();
            transformMatrix.PathGeometry.AddGeometry(new PathGeometry(new[] { new PathFigure(new Point(startXOffset, 0), new[] { new LineSegment(new Point(endXOffset, 0), true) }, false) }));
            transformMatrix.Duration = new Duration(TimeSpan.FromSeconds(0.15));
            return(transformMatrix);
        }
Example #6
0
        /// <summary>
        /// 路径走向
        /// </summary>
        /// <param name="orientation">0正向 1反向</param>
        /// <param name="data">路径数据</param>
        private void MatrixStory(int orientation, string data, int durationTime)
        {
            Border border = new Border();

            border.Width      = 10;
            border.Height     = 10;
            border.Visibility = Visibility.Collapsed;
            if (orientation == 0)
            {
                border.Background = new SolidColorBrush(Colors.Blue);
            }
            else
            {
                border.Background = new SolidColorBrush(Colors.Green);
                data = ConvertReverseData(data);
            }

            this.MyCanvas.Children.Add(border);
            Canvas.SetLeft(border, -border.Width / 2);
            Canvas.SetTop(border, -border.Height / 2);
            border.RenderTransformOrigin = new System.Windows.Point(0.5, 0.5);

            MatrixTransform matrix = new MatrixTransform();
            TransformGroup  groups = new TransformGroup();

            groups.Children.Add(matrix);
            border.RenderTransform = groups;
            //NameScope.SetNameScope(this, new NameScope());
            string registname = "matrix" + Guid.NewGuid().ToString().Replace("-", "");

            this.RegisterName(registname, matrix);
            MatrixAnimationUsingPath matrixAnimation = new MatrixAnimationUsingPath();

            matrixAnimation.PathGeometry          = PathGeometry.CreateFromGeometry(Geometry.Parse(data));
            matrixAnimation.Duration              = new Duration(TimeSpan.FromSeconds(durationTime));
            matrixAnimation.DoesRotateWithTangent = true;//旋转
            //matrixAnimation.FillBehavior = FillBehavior.Stop;
            Storyboard story = new Storyboard();

            story.Children.Add(matrixAnimation);
            Storyboard.SetTargetName(matrixAnimation, registname);
            Storyboard.SetTargetProperty(matrixAnimation, new PropertyPath(MatrixTransform.MatrixProperty));

            #region 控制显示与隐藏
            ObjectAnimationUsingKeyFrames ObjectAnimation = new ObjectAnimationUsingKeyFrames();
            ObjectAnimation.Duration = matrixAnimation.Duration;
            DiscreteObjectKeyFrame kf1 = new DiscreteObjectKeyFrame(Visibility.Visible, TimeSpan.FromMilliseconds(1));
            ObjectAnimation.KeyFrames.Add(kf1);
            story.Children.Add(ObjectAnimation);
            //Storyboard.SetTargetName(border, border.Name);
            Storyboard.SetTargetProperty(ObjectAnimation, new PropertyPath(UIElement.VisibilityProperty));
            #endregion
            story.FillBehavior = FillBehavior.Stop;
            story.Begin(border, true);
        }
Example #7
0
        private void animatePlayerMove()
        {
            NameScope.SetNameScope(this, new NameScope());

            MatrixTransform buttonMatrixTransform = new MatrixTransform();

            PlayerGrid.RenderTransform = buttonMatrixTransform;

            this.RegisterName("PlayerMatrixTransform", buttonMatrixTransform);

            // Create the animation path.
            PathGeometry animationPath = new PathGeometry();
            PathFigure   pFigure       = new PathFigure();

            pFigure.StartPoint = new Point(0, 0);
            PolyBezierSegment pBezierSegment = new PolyBezierSegment();

            pBezierSegment.Points.Add(new Point(150, 0));
            pBezierSegment.Points.Add(new Point(175, 0));
            pBezierSegment.Points.Add(new Point(200, 0));
            pBezierSegment.Points.Add(new Point(225, 0));
            pFigure.Segments.Add(pBezierSegment);
            animationPath.Figures.Add(pFigure);

            // Freeze the PathGeometry for performance benefits.
            animationPath.Freeze();

            // Create a MatrixAnimationUsingPath to move the
            // button along the path by animating
            // its MatrixTransform.
            MatrixAnimationUsingPath matrixAnimation =
                new MatrixAnimationUsingPath();

            matrixAnimation.PathGeometry = animationPath;
            matrixAnimation.Duration     = TimeSpan.FromSeconds(1);
            matrixAnimation.AutoReverse  = true;

            // Set the animation to target the Matrix property
            // of the MatrixTransform named "ButtonMatrixTransform".
            Storyboard.SetTargetName(matrixAnimation, "PlayerMatrixTransform");
            Storyboard.SetTargetProperty(matrixAnimation,
                                         new PropertyPath(MatrixTransform.MatrixProperty));

            // Create a Storyboard to contain and apply the animation.
            Storyboard pathAnimationStoryboard = new Storyboard();

            pathAnimationStoryboard.Children.Add(matrixAnimation);

            pathAnimationStoryboard.Completed += pathAnimationStoryboardPAttack_Completed;
            // Start the storyboard.
            AtkButton.IsEnabled = false;
            pathAnimationStoryboard.Begin(this);
        }
Example #8
0
        // currently not in use...
        private void AnimatePutCard2(int iLocationIndex)
        {
            Canvas targetCanves      = GetCanvas(iLocationIndex);
            Point  pointCanvasCorner = targetCanves.PointToScreen(new Point(0, 0));

            // Create the animation path.
            PathGeometry animationPath = new PathGeometry();
            PathFigure   pFigure       = new PathFigure();

            PolyBezierSegment pBezierSegment = new PolyBezierSegment();

            pFigure.StartPoint = new Point(-pointCanvasCorner.X + this.ActualWidth / 2, -pointCanvasCorner.Y);
            pBezierSegment.Points.Add(pFigure.StartPoint);
            pBezierSegment.Points.Add(new Point(0, 0));


            // Create a MatrixTransform. This transform will be used to move the button.
            MatrixTransform matrixTransform = new MatrixTransform();

            targetCanves.RenderTransform = matrixTransform;

            pFigure.Segments.Add(pBezierSegment);
            animationPath.Figures.Add(pFigure);

            // Freeze the PathGeometry for performance benefits.
            animationPath.Freeze();

            // Create a MatrixAnimationUsingPath to move the
            // button along the path by animating its MatrixTransform.
            MatrixAnimationUsingPath matrixAnimation =
                new MatrixAnimationUsingPath();

            matrixAnimation.PathGeometry = animationPath;
            matrixAnimation.Duration     = TimeSpan.FromSeconds(1);

            // Set the animation's DoesRotateWithTangent property
            // to true so that rotates the card in addition to moving it.
            matrixAnimation.DoesRotateWithTangent = true;

            matrixAnimation.Completed += delegate
            {
                // the cards get reversed - there for need animation to flip it...
                DoubleAnimation da = new DoubleAnimation(180, 0, TimeSpan.FromSeconds(0.34));
                RotateTransform rt = new RotateTransform(0, targetCanves.ActualWidth / 2, targetCanves.ActualHeight / 2);//targetCanves.ActualHeight);
                targetCanves.RenderTransform = rt;
                rt.BeginAnimation(RotateTransform.AngleProperty, da);
            };

            matrixTransform.BeginAnimation(MatrixTransform.MatrixProperty, matrixAnimation);
        }
Example #9
0
        private void AnimatePutCard(int iLocationIndex)
        {
            Canvas targetCanves      = GetCanvas(iLocationIndex);
            Point  pointCanvasCorner = targetCanves.PointToScreen(new Point(0, 0));
            Point  pointWindowCorner = PointToScreen(new Point(0, 0));

            // Create the animation path.
            PathGeometry animationPath = new PathGeometry();
            PathFigure   pFigure       = new PathFigure();

            PolyLineSegment pLineSegment = new PolyLineSegment();
            Point           pointStart   = new Point();

            pointStart.X       = pointWindowCorner.X - pointCanvasCorner.X + this.ActualWidth / 2 - targetCanves.ActualHeight / 4;
            pointStart.Y       = pointWindowCorner.Y - pointCanvasCorner.Y - targetCanves.ActualWidth;
            pFigure.StartPoint = pointStart;
            pLineSegment.Points.Add(pFigure.StartPoint);
            pLineSegment.Points.Add(new Point(0, 0));

            // Create a MatrixTransform. This transform will be used to move the button.
            MatrixTransform matrixTransform = new MatrixTransform();

            targetCanves.RenderTransform = matrixTransform;

            pFigure.Segments.Add(pLineSegment);
            animationPath.Figures.Add(pFigure);

            // Freeze the PathGeometry for performance benefits.
            animationPath.Freeze();

            // Create a MatrixAnimationUsingPath to move the
            // button along the path by animating its MatrixTransform.
            MatrixAnimationUsingPath matrixAnimation = new MatrixAnimationUsingPath();

            matrixAnimation.PathGeometry = animationPath;
            matrixAnimation.Duration     = TimeSpan.FromSeconds(iAnimationPutCardTime);

            DoubleAnimation doubleAnimation = new DoubleAnimation(90, 360, TimeSpan.FromSeconds(iAnimationPutCardTime));
            RotateTransform renderTransform = new RotateTransform(0, targetCanves.ActualWidth / 2, targetCanves.ActualHeight / 2);//targetCanves.ActualHeight);

            targetCanves.Children[0].RenderTransform = renderTransform;
            renderTransform.BeginAnimation(RotateTransform.AngleProperty, doubleAnimation);

            //matrixAnimation.DoesRotateWithTangent = true;
            matrixTransform.BeginAnimation(MatrixTransform.MatrixProperty, matrixAnimation);
        }
Example #10
0
        // this is always called from ui thread
        public void Send()
        {
            Canvas.Children.Add(View);
            View.Loaded    += View_Loaded;
            View.Visibility = Visibility.Hidden;
            View.InvalidateMeasure();
            View.InvalidateVisual();

            NameScope.SetNameScope(Canvas, new NameScope());

            MatrixTransform buttonMatrixTransform = new MatrixTransform();

            View.RenderTransform = buttonMatrixTransform;

            string transformName = "ButtonMatrixTransform";

            Canvas.RegisterName(transformName, buttonMatrixTransform);

            MatrixAnimationUsingPath matrixAnimation = new MatrixAnimationUsingPath()
            {
                PathGeometry          = GetAnimationPathGeometry(new Point(-View.Width / 2, -View.Height / 2)),
                DoesRotateWithTangent = false,
                IsOffsetCumulative    = true,
                IsAdditive            = true,
                Duration       = TimeSpan.FromMilliseconds(Connection.Latency),
                RepeatBehavior = new RepeatBehavior(1)
            };

            Storyboard.SetTargetName(matrixAnimation, transformName);
            Storyboard.SetTargetProperty(matrixAnimation, new PropertyPath(MatrixTransform.MatrixProperty));

            Storyboard packetAnimationStoryboard = new Storyboard();

            packetAnimationStoryboard.Children.Add(matrixAnimation);


            packetAnimationStoryboard.Completed += pathAnimationStoryboard_Completed;
            packetAnimationStoryboard.Begin(Canvas);

            packetAnimationStoryboard.Freeze();
            matrixAnimation.Freeze();

            View.Visibility = Visibility.Visible;
        }
Example #11
0
File: Train.cs Project: M0N3/Subway
        internal void Animate(Subway subway)
        {
            pathAnimationStoryboard = new Storyboard();
            Start = true;
            MatrixTransform buttonMatrixTransform = new MatrixTransform();

            this.TrainPath.RenderTransform = buttonMatrixTransform;
            NameScope.SetNameScope(this, new NameScope());
            RectangleGeometry rc = TrainPath.Data as RectangleGeometry;
            EllipseGeometry   e  = subway.GetRailways.ElementAt(lineNumber).GetStations.ElementAt(id).ellipsePath.Data as EllipseGeometry;
            Point             c  = e.Center;

            rc.Rect = new Rect(c.X, c.Y, 30, 30);
            this.RegisterName("ButtonMatrixTransform", buttonMatrixTransform);
            PathGeometry animationPath = new PathGeometry();

            if (Back)
            {
                animationPath = subway.GetRailways.ElementAt(lineNumber).GetStations.ElementAt(id).endLinePath.Data as PathGeometry;
            }
            else
            {
                if (subway.GetRailways.ElementAt(lineNumber).GetStations.ElementAt(id).startLinePath != null)
                {
                    animationPath = subway.GetRailways.ElementAt(lineNumber).GetStations.ElementAt(id).startLinePath.Data as PathGeometry;
                }
            }
            Point p = subway.GetRailways.ElementAt(lineNumber).GetStations.ElementAt(id).Coordinate;

            rc.Rect = new Rect(rc.Rect.X - p.X - 15, rc.Rect.Y - p.Y - 15, 30, 30);
            MatrixAnimationUsingPath matrixAnimation =
                new MatrixAnimationUsingPath();

            matrixAnimation.PathGeometry          = animationPath;
            matrixAnimation.Duration              = TimeSpan.FromSeconds(travelTime);
            matrixAnimation.DoesRotateWithTangent = true;
            Storyboard.SetTargetName(matrixAnimation, "ButtonMatrixTransform");
            Storyboard.SetTargetProperty(matrixAnimation,
                                         new PropertyPath(MatrixTransform.MatrixProperty));
            pathAnimationStoryboard.Children.Add(matrixAnimation);
            pathAnimationStoryboard.Begin(this);
        }
        private void Button_Forward_click(object sender, RoutedEventArgs e)
        {
            if (panels.Count > 0 && currentPanelNumber + 1 <= panels.Count - 1)
            {
                currentPanelNumber += 1;
                var currentPanel = panels[currentPanelNumber];
                var pannelToHide = panels[currentPanelNumber - 1];
                ContainerGrid.Children.Add(currentPanel);


                MatrixAnimationUsingPath transformMatrix1 = CreatematrixAnimationTransform(ContainerGrid.ActualWidth, 0);
                MatrixAnimationUsingPath transformMatrix2 = CreatematrixAnimationTransform(0, -ContainerGrid.ActualWidth);
                transformMatrix2.Completed += (obj, arg) =>
                {
                    ContainerGrid.Children.RemoveAt(0);
                };

                StartAnimation(currentPanel, pannelToHide, transformMatrix1, transformMatrix2);
            }
        }
Example #13
0
        private void AnimateMoveCard(int iLocationFrom, int iLocationTo)
        {
            Canvas canvesFrom            = GetCanvas(iLocationFrom);
            Point  pointCanvasCornerFrom = canvesFrom.PointToScreen(new Point(0, 0));
            Canvas canvesTo            = GetCanvas(iLocationTo);
            Point  pointCanvasCornerTo = canvesTo.PointToScreen(new Point(0, 0));

            // Create the animation path.
            PathGeometry animationPath = new PathGeometry();
            PathFigure   pFigure       = new PathFigure();

            PolyLineSegment pLineSegment = new PolyLineSegment();

            pFigure.StartPoint = new Point(0, 0);
            pLineSegment.Points.Add(pFigure.StartPoint);
            pLineSegment.Points.Add(new Point(pointCanvasCornerTo.X - pointCanvasCornerFrom.X, pointCanvasCornerTo.Y - pointCanvasCornerFrom.Y));

            // Create a MatrixTransform. This transform will be used to move the button.
            MatrixTransform matrixTransform = new MatrixTransform();

            pFigure.Segments.Add(pLineSegment);
            animationPath.Figures.Add(pFigure);

            // Freeze the PathGeometry for performance benefits.
            animationPath.Freeze();

            // Create a MatrixAnimationUsingPath to move the
            // button along the path by animating its MatrixTransform.
            MatrixAnimationUsingPath matrixAnimation = new MatrixAnimationUsingPath();

            matrixAnimation.PathGeometry = animationPath;
            matrixAnimation.Duration     = TimeSpan.FromSeconds(iAnimationRemoveCardTime);

            canvesFrom.Children[0].RenderTransform = matrixTransform;
            matrixAnimation.Completed += delegate
            {
                MoveCard(iLocationFrom, iLocationTo);
            };

            matrixTransform.BeginAnimation(MatrixTransform.MatrixProperty, matrixAnimation);
        }
Example #14
0
        private void AnimatePutCardMiddleOrRight(int iLocationIndex)
        {
            Canvas targetCanves      = GetCanvas(iLocationIndex);
            Point  pointCanvasCorner = targetCanves.PointToScreen(new Point(0, 0));

            // Create the animation path.
            PathGeometry animationPath = new PathGeometry();
            PathFigure   pFigure       = new PathFigure();

            PolyBezierSegment pBezierSegment = new PolyBezierSegment();

            pFigure.StartPoint = new Point(-pointCanvasCorner.X + this.ActualWidth / 2, -pointCanvasCorner.Y);
            pBezierSegment.Points.Add(pFigure.StartPoint);
            pBezierSegment.Points.Add(new Point(-targetCanves.ActualWidth, 0));
            pBezierSegment.Points.Add(new Point(0, 0));


            // Create a MatrixTransform. This transform will be used to move the button.
            MatrixTransform matrixTransform = new MatrixTransform();

            targetCanves.RenderTransform = matrixTransform;

            pFigure.Segments.Add(pBezierSegment);
            animationPath.Figures.Add(pFigure);

            // Freeze the PathGeometry for performance benefits.
            animationPath.Freeze();

            // Create a MatrixAnimationUsingPath to move the
            // button along the path by animating its MatrixTransform.
            MatrixAnimationUsingPath matrixAnimation =
                new MatrixAnimationUsingPath();

            matrixAnimation.PathGeometry = animationPath;
            matrixAnimation.Duration     = TimeSpan.FromSeconds(iAnimationPutCardTime);

            // Set the animation's DoesRotateWithTangent property
            // to true so that rotates the card in addition to moving it.
            matrixAnimation.DoesRotateWithTangent = true;
            matrixTransform.BeginAnimation(MatrixTransform.MatrixProperty, matrixAnimation);
        }
        private void rocketImageInit()
        {
            try
            {
                img = new Image
                {
                    Width     = 50,
                    Height    = 10,
                    MinWidth  = 50,
                    MinHeight = 10,
                    Stretch   = Stretch.UniformToFill,
                    Cursor    = Cursors.Hand,
                    Source    = new BitmapImage(new Uri(@"pack://application:,,/Images/Misc/Rockets.png")),
                };

                MatrixAnimationUsingPath matrixAnimation =
                    new MatrixAnimationUsingPath();
                matrixAnimation.PathGeometry          = rocketPath;
                matrixAnimation.Duration              = TimeSpan.FromSeconds(10);
                matrixAnimation.RepeatBehavior        = RepeatBehavior.Forever;
                matrixAnimation.DoesRotateWithTangent = true;

                Storyboard.SetTargetName(matrixAnimation, "imgMatrixTransform");
                Storyboard.SetTargetProperty(matrixAnimation, new PropertyPath(MatrixTransform.MatrixProperty));

                pathAnimationStoryboard = new Storyboard();
                pathAnimationStoryboard.Children.Add(matrixAnimation);

                imgMatrixTransform  = new MatrixTransform();
                img.RenderTransform = imgMatrixTransform;
                this.RegisterName("imgMatrixTransform", imgMatrixTransform);
                this.RegisterName("imgRocket", img);
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #16
0
        //Convert points[] to storyboard
        private Storyboard CreateStoryBoard(Point[] points)
        {
            MatrixTransform buttonMatrixTransform = new MatrixTransform();

            BusImage.RenderTransform = buttonMatrixTransform;
            Parent.RegisterName("MatrixTransform" + BusLineNo, buttonMatrixTransform);

            PathGeometry animationPath = new PathGeometry();
            PathFigure   pFigure       = new PathFigure();

            pFigure.StartPoint = points[0];
            PolyLineSegment pLineSegment = new PolyLineSegment();

            for (int i = 1; i < points.Length; i++)
            {
                pLineSegment.Points.Add(points[i]);
            }
            pFigure.Segments.Add(pLineSegment);
            animationPath.Figures.Add(pFigure);

            animationPath.Freeze();

            MatrixAnimationUsingPath matrixAnimation = new MatrixAnimationUsingPath();

            matrixAnimation.PathGeometry = animationPath;
            matrixAnimation.Duration     = TimeSpan.FromSeconds(Duration(SPEED, points));

            matrixAnimation.DoesRotateWithTangent = true;
            Storyboard.SetTargetName(matrixAnimation, "MatrixTransform" + BusLineNo);
            Storyboard.SetTargetProperty(matrixAnimation, new PropertyPath(MatrixTransform.MatrixProperty));

            this.pasb = new Storyboard();
            this.pasb.Children.Add(matrixAnimation);
            this.pasb.Completed += new EventHandler(nextStop);

            return(pasb);
        }
        private void RenderAnimation()
        {
            if (AnimationThumb != null)
            {
                NameScope.SetNameScope(this, new NameScope());

                Storyboard story = new Storyboard();
                AnimationThumb.RenderTransformOrigin = new Point(0.5, 0.5);
                MatrixTransform matrix = new MatrixTransform();
                TransformGroup  groups = new TransformGroup();
                groups.Children.Add(matrix);
                AnimationThumb.RenderTransform = groups;
                MatrixAnimationUsingPath matrixAnimation = new MatrixAnimationUsingPath();
                matrixAnimation.PathGeometry          = AnimationData;
                matrixAnimation.Duration              = new Duration(TimeSpan.FromSeconds(5));
                matrixAnimation.DoesRotateWithTangent = true;//旋转
                matrixAnimation.RepeatBehavior        = RepeatBehavior.Forever;
                story.Children.Add(matrixAnimation);
                this.RegisterName("matrix", matrix);
                Storyboard.SetTargetName(matrixAnimation, "matrix");
                Storyboard.SetTargetProperty(matrixAnimation, new PropertyPath(MatrixTransform.MatrixProperty));
                story.Begin(this);
            }
        }
Example #18
0
        /// <summary>
        /// metoda animujaca obiekty klasy Train
        /// </summary>
        /// <param name="train"></param>
        public void MoveTrainMatrix(Train train)
        {
            //stworzenie MatrixTransform przy uzyciu ktorego pociag bedzie poruszal sie na Canvasie
            MatrixTransform ImageMatrixTransform = new MatrixTransform();

            train.TrainImage.RenderTransform = ImageMatrixTransform;

            //nadanie ID pociagowi by Storyboard mogl sie do niego odwolac
            string id = Guid.NewGuid().ToString().Substring(0, 4);

            mainWindow.RegisterName($"ImageMatrixTransform{id}", ImageMatrixTransform);

            //stworzenie sciezki po ktorej bedzie poruszal sie pociag
            PathGeometry animationPath = new PathGeometry();
            PathFigure   pFigure       = new PathFigure();

            //PolyBezierSegment przemieszcza pociagu po wskazanych punktach
            PolyBezierSegment pBezierSegment = new PolyBezierSegment();

            //punkty po ktorych bedzie poruszal sie pociag w zaleznosci od wylosowanego dla niego kierunku
            switch (train.TrainDirection)
            {
            case Train.Direction.None:

                break;

            case Train.Direction.Left:
                //punkt w ktorym pojawi sie pociag zaraz po stworzeniu
                pFigure.StartPoint = new Point(800, 230);

                pBezierSegment.Points.Add(new Point(700, 230));
                pBezierSegment.Points.Add(new Point(400, 230));
                pBezierSegment.Points.Add(new Point(-100, 230));

                break;

            case Train.Direction.Right:
                //punkt w ktorym pojawi sie pociag zaraz po stworzeniu
                pFigure.StartPoint = new Point(13, 230);

                pBezierSegment.Points.Add(new Point(100, 230));
                pBezierSegment.Points.Add(new Point(300, 230));
                pBezierSegment.Points.Add(new Point(950, 230));

                break;

            default:
                break;
            }

            //dodanie punktow do sciezki
            pFigure.Segments.Add(pBezierSegment);
            //dodanie sciezki do sciezki animacji
            animationPath.Figures.Add(pFigure);

            //stworzenie instancji klasy MatrixAnimationUsingPath, ktora przesuwa pociag
            //po sciezce animacji
            MatrixAnimationUsingPath matrixAnimation = new MatrixAnimationUsingPath();

            matrixAnimation.PathGeometry = animationPath;

            //predkosc animacji pociagu
            matrixAnimation.Duration = TimeSpan.FromSeconds(8);

            //ustawienie animacji dla wlasciwosci MatrixTransform obiektu o wskazanym ID
            Storyboard.SetTargetName(matrixAnimation, $"ImageMatrixTransform{id}");
            Storyboard.SetTargetProperty(matrixAnimation, new PropertyPath(MatrixTransform.MatrixProperty));

            //Storyboard kontroluje wszystkie animacje dodane jako jego dzieci
            Storyboard pathAnimationStoryboard = new Storyboard();

            pathAnimationStoryboard.Children.Add(matrixAnimation);
            pathAnimationStoryboard.Completed += TrainAnimationStoryboard_Completed;

            train.Animator = pathAnimationStoryboard;
            pathAnimationStoryboard.Begin(mainWindow, true);
            //ustawienie predkosci animacji dla pociagu
            pathAnimationStoryboard.SetSpeedRatio(mainWindow, train.TrainSpeed);
        }
Example #19
0
        public MatrixAnimationUsingPathDoesRotateWithTangentExample()
        {
            this.Margin = new Thickness(20);

            // Create a NameScope for the page so that
            // we can use Storyboards.
            NameScope.SetNameScope(this, new NameScope());

            // Create a button.
            Button aButton = new Button();

            aButton.MinWidth = 100;
            aButton.Content  = "A Button";

            // Create a MatrixTransform. This transform
            // will be used to move the button.
            MatrixTransform buttonMatrixTransform = new MatrixTransform();

            aButton.RenderTransform = buttonMatrixTransform;

            // Register the transform's name with the page
            // so that it can be targeted by a Storyboard.
            this.RegisterName("ButtonMatrixTransform", buttonMatrixTransform);

            // Create a Canvas to contain the button
            // and add it to the page.
            // Although this example uses a Canvas,
            // any type of panel will work.
            Canvas mainPanel = new Canvas();

            mainPanel.Width  = 400;
            mainPanel.Height = 400;
            mainPanel.Children.Add(aButton);
            this.Content = mainPanel;

            // Create the animation path.
            PathGeometry animationPath = new PathGeometry();
            PathFigure   pFigure       = new PathFigure();

            pFigure.StartPoint = new Point(10, 100);
            PolyBezierSegment pBezierSegment = new PolyBezierSegment();

            pBezierSegment.Points.Add(new Point(35, 0));
            pBezierSegment.Points.Add(new Point(135, 0));
            pBezierSegment.Points.Add(new Point(160, 100));
            pBezierSegment.Points.Add(new Point(180, 190));
            pBezierSegment.Points.Add(new Point(285, 200));
            pBezierSegment.Points.Add(new Point(310, 100));
            pFigure.Segments.Add(pBezierSegment);
            animationPath.Figures.Add(pFigure);

            // Freeze the PathGeometry for performance benefits.
            animationPath.Freeze();

            // Create a MatrixAnimationUsingPath to move the
            // button along the path by animating
            // its MatrixTransform.
            MatrixAnimationUsingPath matrixAnimation =
                new MatrixAnimationUsingPath();

            matrixAnimation.PathGeometry   = animationPath;
            matrixAnimation.Duration       = TimeSpan.FromSeconds(5);
            matrixAnimation.RepeatBehavior = RepeatBehavior.Forever;

            // Set the animation's DoesRotateWithTangent property
            // to true so that rotates the rectangle in addition
            // to moving it.
            matrixAnimation.DoesRotateWithTangent = true;

            // Set the animation to target the Matrix property
            // of the MatrixTransform named "ButtonMatrixTransform".
            Storyboard.SetTargetName(matrixAnimation, "ButtonMatrixTransform");
            Storyboard.SetTargetProperty(matrixAnimation,
                                         new PropertyPath(MatrixTransform.MatrixProperty));

            // Create a Storyboard to contain and apply the animation.
            Storyboard pathAnimationStoryboard = new Storyboard();

            pathAnimationStoryboard.Children.Add(matrixAnimation);

            // Start the storyboard when the button is loaded.
            aButton.Loaded += delegate(object sender, RoutedEventArgs e)
            {
                // Start the storyboard.
                pathAnimationStoryboard.Begin(this);
            };
        }
Example #20
0
        /// <summary>
        /// 将点加入到动画故事版
        /// </summary>
        /// <param name="runPoint">运动的点</param>
        /// <param name="toEll">达到城市的圆</param>
        /// <param name="sb">故事版</param>
        /// <param name="particlePath">运动轨迹</param>
        /// <param name="l">运动轨迹的直线距离</param>
        /// <param name="from">来自</param>
        /// <param name="toItem">去</param>
        private void AddPointToStoryboard(Grid runPoint, Ellipse toEll, Storyboard sb, Path particlePath, double l, ProvincialCapital from, MapToItem toItem)
        {
            double pointTime    = l / m_Speed;   //点运动所需的时间
            double particleTime = pointTime / 2; //轨迹呈现所需时间(跑的比点快两倍)
            //生成为控件注册名称的guid
            string name = Guid.NewGuid().ToString().Replace("-", "");

            #region 运动的点
            TransformGroup  tfg = new TransformGroup();
            MatrixTransform mtf = new MatrixTransform();
            tfg.Children.Add(mtf);
            TranslateTransform ttf = new TranslateTransform(-runPoint.Width / 2, -runPoint.Height / 2);//纠正最上角沿path运动到中心沿path运动
            tfg.Children.Add(ttf);
            runPoint.RenderTransform = tfg;
            _mapc.RegisterName("m" + name, mtf);

            MatrixAnimationUsingPath maup = new MatrixAnimationUsingPath();
            maup.PathGeometry          = particlePath.Data.GetFlattenedPathGeometry();
            maup.Duration              = new Duration(TimeSpan.FromSeconds(pointTime));
            maup.RepeatBehavior        = RepeatBehavior.Forever;
            maup.AutoReverse           = false;
            maup.IsOffsetCumulative    = false;
            maup.DoesRotateWithTangent = true;//沿切线旋转
            Storyboard.SetTargetName(maup, "m" + name);
            Storyboard.SetTargetProperty(maup, new PropertyPath(MatrixTransform.MatrixProperty));
            sb.Children.Add(maup);
            #endregion

            #region 达到城市的圆
            _mapc.RegisterName("ell" + name, toEll);
            //轨迹到达圆时 圆呈现
            DoubleAnimation ellda = new DoubleAnimation();
            ellda.From         = 0.2;//此处值设置0-1会有不同的呈现效果
            ellda.To           = 1;
            ellda.Duration     = new Duration(TimeSpan.FromSeconds(particleTime));
            ellda.BeginTime    = TimeSpan.FromSeconds(particleTime);//推迟动画开始时间 等轨迹连接到圆时 开始播放圆的呈现动画
            ellda.FillBehavior = FillBehavior.HoldEnd;
            Storyboard.SetTargetName(ellda, "ell" + name);
            Storyboard.SetTargetProperty(ellda, new PropertyPath(Ellipse.OpacityProperty));
            sb.Children.Add(ellda);
            //圆呈放射状
            RadialGradientBrush rgBrush = new RadialGradientBrush();
            GradientStop        gStop0  = new GradientStop(Color.FromArgb(255, 0, 0, 0), 0);
            //此为控制点 color的a值设为0 off值走0-1 透明部分向外放射 初始设为255是为了初始化效果 开始不呈放射状 等跑动的点运动到城市的圆后 color的a值才设为0开始呈现放射动画
            GradientStop gStopT = new GradientStop(Color.FromArgb(255, 0, 0, 0), 0);
            GradientStop gStop1 = new GradientStop(Color.FromArgb(255, 0, 0, 0), 1);
            rgBrush.GradientStops.Add(gStop0);
            rgBrush.GradientStops.Add(gStopT);
            rgBrush.GradientStops.Add(gStop1);
            toEll.OpacityMask = rgBrush;
            _mapc.RegisterName("e" + name, gStopT);
            //跑动的点达到城市的圆时 控制点由不透明变为透明 color的a值设为0 动画时间为0
            ColorAnimation ca = new ColorAnimation();
            ca.To           = Color.FromArgb(0, 0, 0, 0);
            ca.Duration     = new Duration(TimeSpan.FromSeconds(0));
            ca.BeginTime    = TimeSpan.FromSeconds(pointTime);
            ca.FillBehavior = FillBehavior.HoldEnd;
            Storyboard.SetTargetName(ca, "e" + name);
            Storyboard.SetTargetProperty(ca, new PropertyPath(GradientStop.ColorProperty));
            sb.Children.Add(ca);
            //点达到城市的圆时 呈现放射状动画 控制点的off值走0-1 透明部分向外放射
            DoubleAnimation eda = new DoubleAnimation();
            eda.To             = 1;
            eda.Duration       = new Duration(TimeSpan.FromSeconds(2));
            eda.RepeatBehavior = RepeatBehavior.Forever;
            eda.BeginTime      = TimeSpan.FromSeconds(particleTime);
            Storyboard.SetTargetName(eda, "e" + name);
            Storyboard.SetTargetProperty(eda, new PropertyPath(GradientStop.OffsetProperty));
            sb.Children.Add(eda);
            #endregion

            #region 运动轨迹
            //找到渐变的起点和终点
            Point startPoint = GetProvincialCapitalPoint(from);
            Point endPoint   = GetProvincialCapitalPoint(toItem.To);
            Point start      = new Point(0, 0);
            Point end        = new Point(1, 1);
            if (startPoint.X > endPoint.X)
            {
                start.X = 1;
                end.X   = 0;
            }
            if (startPoint.Y > endPoint.Y)
            {
                start.Y = 1;
                end.Y   = 0;
            }
            LinearGradientBrush lgBrush = new LinearGradientBrush();
            lgBrush.StartPoint = start;
            lgBrush.EndPoint   = end;
            GradientStop lgStop0 = new GradientStop(Color.FromArgb(255, 0, 0, 0), 0);
            GradientStop lgStop1 = new GradientStop(Color.FromArgb(0, 0, 0, 0), 0);
            lgBrush.GradientStops.Add(lgStop0);
            lgBrush.GradientStops.Add(lgStop1);
            particlePath.OpacityMask = lgBrush;
            _mapc.RegisterName("p0" + name, lgStop0);
            _mapc.RegisterName("p1" + name, lgStop1);
            //运动轨迹呈现
            DoubleAnimation pda0 = new DoubleAnimation();
            pda0.To           = 1;
            pda0.Duration     = new Duration(TimeSpan.FromSeconds(particleTime));
            pda0.FillBehavior = FillBehavior.HoldEnd;
            Storyboard.SetTargetName(pda0, "p0" + name);
            Storyboard.SetTargetProperty(pda0, new PropertyPath(GradientStop.OffsetProperty));
            sb.Children.Add(pda0);
            DoubleAnimation pda1 = new DoubleAnimation();
            //pda1.From = 0.5; //此处解开注释 值设为0-1 会有不同的轨迹呈现效果
            pda1.To           = 1;
            pda1.Duration     = new Duration(TimeSpan.FromSeconds(particleTime));
            pda1.FillBehavior = FillBehavior.HoldEnd;
            Storyboard.SetTargetName(pda1, "p1" + name);
            Storyboard.SetTargetProperty(pda1, new PropertyPath(GradientStop.OffsetProperty));
            sb.Children.Add(pda1);
            #endregion
        }
Example #21
0
        //Border border = new Border();
        /// <summary>
        ///
        /// </summary>
        /// <param name="orientation">0正向 1反向</param>
        /// <param name="data">路径数据</param>
        private void MatrixStory(UserControls.AgvCar agvCar, PathModel pathModel)
        {
            //border.Width = 10;
            //border.Height = 10;
            //border.Visibility = Visibility.Visible;
            //if (orientation == 0)
            //{
            //    border.Background = new SolidColorBrush(Colors.Blue);
            //}
            //else
            //{
            //    border.Background = new SolidColorBrush(Colors.Green);
            //}
            //if (!this.MainContent.Children.Contains(agvCar))
            //{
            //    this.MainContent.Children.Add(agvCar);

            //}
            Canvas.SetLeft(agvCar, -agvCar.Width / 2);
            Canvas.SetTop(agvCar, -agvCar.Height / 2);
            agvCar.RenderTransformOrigin = new Point(0.5, 0.5);

            MatrixTransform matrix = new MatrixTransform();
            TransformGroup  groups = new TransformGroup();

            groups.Children.Add(matrix);
            agvCar.RenderTransform = groups;
            //NameScope.SetNameScope(this, new NameScope());
            string registname = "matrix" + Guid.NewGuid().ToString().Replace("-", "");

            agvCar.RegisterName(registname, matrix);
            MatrixAnimationUsingPath matrixAnimation = new MatrixAnimationUsingPath();

            //matrixAnimation.PathGeometry = PathGeometry.CreateFromGeometry(Geometry.Parse(    (  mainContent.FindChild(path.Key.ToString() + path.Value.ToString()) as Path )  .Data       ));
            matrixAnimation.PathGeometry          = PathGeometry.CreateFromGeometry(mainContent.FindChild <Path>(pathModel.Name).Data);
            matrixAnimation.Duration              = new Duration(TimeSpan.FromSeconds(10));
            matrixAnimation.DoesRotateWithTangent = false;//旋转
            matrixAnimation.AccelerationRatio     = 0.4;
            matrixAnimation.DecelerationRatio     = 0.4;
            //matrixAnimation.FillBehavior
            //matrixAnimation.FillBehavior = FillBehavior.Stop;
            Storyboard story = new Storyboard();

            story.Children.Add(matrixAnimation);
            Storyboard.SetTargetName(matrixAnimation, registname);
            Storyboard.SetTargetProperty(matrixAnimation, new PropertyPath(MatrixTransform.MatrixProperty));

            //#region 控制显示与隐藏
            //ObjectAnimationUsingKeyFrames ObjectAnimation = new ObjectAnimationUsingKeyFrames();
            //ObjectAnimation.Duration = matrixAnimation.Duration;
            //DiscreteObjectKeyFrame kf1 = new DiscreteObjectKeyFrame(Visibility.Visible, TimeSpan.FromMilliseconds(1));
            //ObjectAnimation.KeyFrames.Add(kf1);
            //story.Children.Add(ObjectAnimation);
            ////Storyboard.SetTargetName(border, border.Name);
            //Storyboard.SetTargetProperty(ObjectAnimation, new PropertyPath(UIElement.VisibilityProperty));
            //#endregion

            story.FillBehavior = FillBehavior.HoldEnd;
            agvCar.Tag         = story;

            story.Begin(agvCar, true);
        }
Example #22
0
        private void animatePlayerRanged()
        {
            BitmapImage arrowSource = new BitmapImage();

            arrowSource.BeginInit();
            arrowSource.UriSource = new Uri("/Resources/PArrow_25x16_Trans.png", UriKind.Relative);
            arrowSource.EndInit();
            arrow        = new Image();
            arrow.Source = arrowSource;

            PArrowGrid.Children.Add(arrow);

            NameScope.SetNameScope(this, new NameScope());

            MatrixTransform buttonMatrixTransform = new MatrixTransform();

            PArrowGrid.RenderTransform = buttonMatrixTransform;

            this.RegisterName("FireMatrixTransform", buttonMatrixTransform);

            // Create the animation path.
            PathGeometry animationPath = new PathGeometry();
            PathFigure   pFigure       = new PathFigure();

            pFigure.StartPoint = new Point(0, 0);
            PolyBezierSegment pBezierSegment = new PolyBezierSegment();

            pBezierSegment.Points.Add(new Point(150, 0));
            pBezierSegment.Points.Add(new Point(175, 0));
            pBezierSegment.Points.Add(new Point(200, 0));
            pBezierSegment.Points.Add(new Point(225, 0));
            pFigure.Segments.Add(pBezierSegment);
            animationPath.Figures.Add(pFigure);

            // Freeze the PathGeometry for performance benefits.
            animationPath.Freeze();

            // Create a MatrixAnimationUsingPath to move the
            // button along the path by animating
            // its MatrixTransform.
            MatrixAnimationUsingPath matrixAnimation =
                new MatrixAnimationUsingPath();

            matrixAnimation.PathGeometry = animationPath;
            matrixAnimation.Duration     = TimeSpan.FromSeconds(.5);

            // Set the animation to target the Matrix property
            // of the MatrixTransform named "ButtonMatrixTransform".
            Storyboard.SetTargetName(matrixAnimation, "FireMatrixTransform");
            Storyboard.SetTargetProperty(matrixAnimation,
                                         new PropertyPath(MatrixTransform.MatrixProperty));

            // Create a Storyboard to contain and apply the animation.
            Storyboard pathAnimationStoryboard = new Storyboard();

            pathAnimationStoryboard.Children.Add(matrixAnimation);

            pathAnimationStoryboard.Completed += pathAnimationStoryboardRangedMove_Completed;
            // Start the storyboard.
            AtkButton.IsEnabled = false;
            pathAnimationStoryboard.Begin(this);
        }
        private void DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
        {
            Thumb thumb    = sender as Thumb;
            int   position = -1;

            if (thumb == thumb_player)
            {
                position = 0;
            }
            else if (thumb == thumb_paved)
            {
                position = 1;
            }
            if (position == -1)
            {
                return;
            }
            double left = Canvas.GetLeft(thumb);

            if (left > gd.ActualWidth / 3 * 2 || (gMain.Children[0] as BaseUserControl).filePath.Equals(String.Empty))
            {
                thumb.RenderTransformOrigin = new Point(0.5, 0.5);
                if (position == 0)
                {
                    thumb.RenderTransform = MatrixTransform_01;
                }
                else if (position == 1)
                {
                    thumb.RenderTransform = MatrixTransform_02;
                }
                double top = Canvas.GetTop(thumb);

                QuadraticBezierSegment quadraticBezierSegment = new QuadraticBezierSegment();
                quadraticBezierSegment.Point1 = new Point((startPoints[position].X - left) / 2, (top - startPoints[position].Y) / 2);
                quadraticBezierSegment.Point2 = new Point(startPoints[position].X - left, startPoints[position].Y - top);
                PathSegmentCollection pathSegmentCollection = new PathSegmentCollection();
                pathSegmentCollection.Add(quadraticBezierSegment);

                PathFigure pathFigure = new PathFigure();
                pathFigure.StartPoint = new Point(0, 0);
                pathFigure.Segments   = pathSegmentCollection;

                PathFigureCollection pathFigureCollection = new PathFigureCollection();
                pathFigureCollection.Add(pathFigure);

                PathGeometry pathGeometry = new PathGeometry();
                pathGeometry.Figures = pathFigureCollection;

                MatrixAnimationUsingPath matrixAnimation = new MatrixAnimationUsingPath();
                matrixAnimation.PathGeometry = pathGeometry;
                //动画的路径
                matrixAnimation.Duration   = TimeSpan.FromSeconds(0.5);
                matrixAnimation.Completed += MatrixAnimation_Completed;
                //matrixAnimation.FillBehavior = FillBehavior.Stop;
                //matrixAnimation.RepeatBehavior = RepeatBehavior.Forever;
                //matrixAnimation.DoesRotateWithTangent = true;
                //Storyboard.SetTarget(matrixAnimation, thumb);
                if (position == 0)
                {
                    Storyboard.SetTargetName(matrixAnimation, "MatrixTransform_01");//动画的对象
                }
                else if (position == 1)
                {
                    Storyboard.SetTargetName(matrixAnimation, "MatrixTransform_02");//动画的对象
                }
                Storyboard.SetTargetProperty(matrixAnimation, new PropertyPath(MatrixTransform.MatrixProperty));

                Storyboard pathAnimationStoryboard = new Storyboard();
                pathAnimationStoryboard.Children.Add(matrixAnimation);
                pathAnimationStoryboard.Begin(this);
            }
            else
            {
                BaseMakerLightUserControl baseMakerLightUserControl = gMain.Children[0] as BaseMakerLightUserControl;
                UserControl userControl = null;
                if (position == 0)
                {
                    //加入播放器页面
                    PlayerUserControl playerUserControl = new PlayerUserControl(mw);
                    playerUserControl.SetData(baseMakerLightUserControl.GetData());
                    userControl = playerUserControl;
                }
                else if (position == 1)
                {
                    //加入平铺页面
                    //PavedUserControl pavedUserControl = new PavedUserControl(this,baseMakerLightUserControl.GetData());
                    //userControl = pavedUserControl;
                }
                gMost.Children.Add(userControl);
                DoubleAnimation daV = new DoubleAnimation(0, 1, new Duration(TimeSpan.FromSeconds(0.5)));
                userControl.BeginAnimation(OpacityProperty, daV);
                //回原位
                ToolBackToOld(thumb, position);
            }
        }
        private void StartAnimation(StackPanel currentPanel, StackPanel pannelToHide, MatrixAnimationUsingPath transformMatrix1, MatrixAnimationUsingPath transformMatrix2)
        {
            Storyboard.SetTarget(transformMatrix1, currentPanel);
            Storyboard.SetTargetProperty(transformMatrix1,
                                         new PropertyPath("RenderTransform.Matrix"));

            Storyboard.SetTarget(transformMatrix2, pannelToHide);
            Storyboard.SetTargetProperty(transformMatrix2,
                                         new PropertyPath("RenderTransform.Matrix"));

            Storyboard myStoryboard = new Storyboard();

            myStoryboard.Children.Add(transformMatrix1);
            myStoryboard.Children.Add(transformMatrix2);
            myStoryboard.Begin(this);
        }
Example #25
0
        /// <summary>
        /// metoda przemiesczajaca obiekty klasy Car po Canvasie
        /// </summary>
        /// <param name="car"></param>
        public void MoveCarMatrix(Car car)
        {
            //stworzenie MatrixTransform przy uzyciu ktorego samochodziki beda przemiszczaly sie po Canvasie
            MatrixTransform ImageMatrixTransform = new MatrixTransform();

            car.CarImage.RenderTransform = ImageMatrixTransform;

            //nadanie ID samochodzikowi by Storyboard mogl sie do niego odwolac
            string id = Guid.NewGuid().ToString().Substring(0, 4);

            mainWindow.RegisterName($"ImageMatrixTransform{id}", ImageMatrixTransform);

            //stworzenie sciezki po ktorej beda poruszaly sie samochodziki
            PathGeometry animationPath = new PathGeometry();
            PathFigure   pFigure       = new PathFigure();

            //punkt w ktorym pojawiaja sie samochodziki po stworzeniu
            pFigure.StartPoint = new Point(5, 201);
            //PolyBezierSegment dla poruszania sie samochodziku po wyznaczonej sciezce
            PolyBezierSegment pBezierSegment = new PolyBezierSegment();

            //punkty do ktorych kolejno beda dazyly samochodziki z punktu startowego
            pBezierSegment.Points.Add(new Point(10, 201));
            pBezierSegment.Points.Add(new Point(300, 201));
            pBezierSegment.Points.Add(new Point(630, 201));

            pBezierSegment.Points.Add(new Point(640, 219));
            pBezierSegment.Points.Add(new Point(690, 242));
            pBezierSegment.Points.Add(new Point(645, 335));

            pBezierSegment.Points.Add(new Point(535, 345));
            pBezierSegment.Points.Add(new Point(300, 345));
            pBezierSegment.Points.Add(new Point(160, 345));

            pBezierSegment.Points.Add(new Point(80, 370));
            pBezierSegment.Points.Add(new Point(70, 450));
            pBezierSegment.Points.Add(new Point(120, 540));

            pBezierSegment.Points.Add(new Point(184, 566));
            pBezierSegment.Points.Add(new Point(300, 566));
            pBezierSegment.Points.Add(new Point(920, 566));

            //dodanie punktow do sciezki
            pFigure.Segments.Add(pBezierSegment);
            //dodanie sciezki do sciezki animacji
            animationPath.Figures.Add(pFigure);

            //stworzenie instancji klasy MatrixAnimationUsingPath, kotra przemieszcza samochodzik
            //po sciezce animacji
            MatrixAnimationUsingPath matrixAnimation = new MatrixAnimationUsingPath();

            matrixAnimation.PathGeometry = animationPath;

            //predkosc animacji samochodzikow
            matrixAnimation.Duration = TimeSpan.FromSeconds(8);

            //ustawienie animacji dla wlasciwosci MatrixTransform obiektu o wskazanym ID
            Storyboard.SetTargetName(matrixAnimation, $"ImageMatrixTransform{id}");
            Storyboard.SetTargetProperty(matrixAnimation, new PropertyPath(MatrixTransform.MatrixProperty));

            //Storyboard kontroluje wszystkie animacje dodane jako jego dzieci
            Storyboard pathAnimationStoryboard = new Storyboard();

            pathAnimationStoryboard.Children.Add(matrixAnimation);

            //aktualny progres animacji
            pathAnimationStoryboard.Completed += CarAnimationStoryboard_Completed;

            car.Animator        = pathAnimationStoryboard;
            car.matrixTransform = matrixAnimation;

            pathAnimationStoryboard.Begin(mainWindow, true);
            //ustalenie predkosci animacji dla animowanego samochodziku
            pathAnimationStoryboard.SetSpeedRatio(mainWindow, car.CarSpeed);
        }