Example #1
0
        private void AnimateMoveBall(Ball ball, Cell fromCell, Cell toCell)
        {
            List<Point> path = _table.FindPath(fromCell, toCell).Select(c => c.BallPoint).ToList();
            _table.StartMoveBallTo(ball, toCell);

            TimeSpan duration = TimeSpan.FromSeconds(AnimMovingBallStep * path.Count);
            DoubleAnimationUsingPath animX;
            _animMovingBall = new Storyboard {
                Children = {
                    (animX = new DoubleAnimationUsingPath {
                        PathGeometry = new PathGeometry {
                            Figures = new PathFigureCollection {
                                new PathFigure(fromCell.BallPoint, path.Select(p => new LineSegment(p, false)), false)
                            }
                        },
                        Duration = new Duration(duration),
                        AccelerationRatio = .1, DecelerationRatio = .7, Source = PathAnimationSource.X,
                    }.SetTarget(Canvas.LeftProperty.ToPath())),
                    animX.CloneForY().SetTarget(Canvas.TopProperty.ToPath()),
                }
            };
            _animMovingBall.AddCompleted(AnimMove_OnCompleted).Begin(lstBalls.GetItemContainer(toCell.Ball));
        }