Esempio n. 1
0
        public Trail(Vector from, Vector to, double speed, Color color1, Color color2)
        {
            var trailVector = (to - from).Normalized() * TRAIL_SIZE;

            color1.A = 0;
            var brush = new LinearGradientBrush(color1, color2, from.ToPoint(), to.ToPoint());

            brush.MappingMode = BrushMappingMode.Absolute;

            var line = new Line();

            line.Stroke             = brush;
            line.StrokeThickness    = 2;
            line.StrokeStartLineCap = PenLineCap.Round;
            line.StrokeEndLineCap   = PenLineCap.Round;

            line.X1 = from.X;
            line.Y1 = from.Y;
            line.X2 = from.X;
            line.Y2 = from.Y;

            position = Lerp.Speed(from, to, speed, p =>
            {
                line.X2 = p.X;
                line.Y2 = p.Y;
                Moving?.Invoke(p);
            });

            var brushPosition = Lerp.Speed(from, to + trailVector, speed, p =>
            {
                brush.StartPoint = (p - trailVector).ToPoint();
                brush.EndPoint   = p;
            });

            position.Completed += () =>
            {
                // Destination reached
                Completed?.Invoke();
            };

            brushPosition.Completed += () =>
            {
                // Trail faded completely
                Faded?.Invoke();
                this.Destroy();
            };

            Add(position);
            Add(brushPosition);
            Add(line);
        }
Esempio n. 2
0
        public void Fade()
        {
            BeginAnimation(OpacityProperty, null);
            FadeStarted?.Invoke(this, EventArgs.Empty);
            var anim = new DoubleAnimation(0, new Duration(TimeSpan.FromSeconds(0.2)))
            {
                FillBehavior = FillBehavior.Stop
            };

            anim.Completed += (sender, args) =>
            {
                Opacity = 0;
                Faded?.Invoke(this, args);
            };
            BeginAnimation(OpacityProperty, anim);
        }