Exemplo n.º 1
0
        /**
         * Add a fake sparkle from a mouse interaction.
         */
        public void AddSparkleFromMouse(Point start, Point end, DateTime startTime)
        {
            if (Math.Abs(start.X - end.X) <= 5 && Math.Abs(start.Y - end.Y) <= 5)
            {
                // only generate moving sparkles
                return;
            }
            MovingSparkle sparkle = new MovingSparkle();

            sparkle.SetSparkle(15, 25, 1);
            sparkle.SetMovement(start.X, start.Y, (end.X - start.X) * 2.0, (end.Y - start.Y) * 2.0, startTime);
            canvas.Children.Add(sparkle.Image);
            sparkles.AddLast(sparkle);
            sparkle.Update(startTime);
        }
Exemplo n.º 2
0
        /**
         * Update the position and size of all sparkles.
         * Remove sparkles that leave the canvas.
         */
        public void Update(DateTime now)
        {
            LinkedListNode <MovingSparkle> node = sparkles.First;

            while (node != null)
            {
                // update sparkle
                MovingSparkle sparkle = node.Value;
                sparkle.Update(now);
                // remove sparkle if outside the canvas
                double left = Canvas.GetLeft(sparkle.Image);
                double top  = Canvas.GetTop(sparkle.Image);
                if (left + sparkle.Image.Width < 0 || left > canvas.ActualWidth ||
                    top + sparkle.Image.Height < 0 || top > canvas.ActualHeight)
                {
                    LinkedListNode <MovingSparkle> next = node.Next;
                    canvas.Children.Remove(sparkle.Image);
                    sparkles.Remove(node);
                    node = next;
                    continue;
                }
                node = node.Next;
            }
        }