Beispiel #1
0
        /// <summary>
        /// Create a sprite that follows a Bezier path.
        ///
        /// Path format is (similar to svg) (g=guidepoint):
        /// g1p1x,g1p1y[space]g2p1x,g2p1y[space]p1x,p1y
        /// g1p2x,g1p2y[space]g2p2x,g2p2y[space]p2x,p2y
        /// etc...
        /// So it's 2 guidepoints followed by end point.
        /// This will follow simple Bezier paths created using GIMP and exported as SVG.
        /// </summary>
        /// <param name="p_startPoint">Point where sprite begins</param>
        /// <param name="p_path">String of points sprite should follow</param>
        /// <param name="p_ratio">double value indicating stepping size as a fraction of distance along path to take with each step</param>
        public BezierSprite(Point p_startPoint, string p_path, double p_ratio)
        {
            startPoint = p_startPoint;

            points = new List <Point>();
            points.Add(p_startPoint);
            points.AddRange(BezierSprite.PointsStringToList(p_path));

            if ((points.Count - 1) % 3 != 0)
            {
                throw new ArgumentException("The number of points in the path must be divisible by 3");
            }

            segmentIndex = 0;
            segmentCount = (points.Count - 1) / 3;

            lengthRatios = new List <LengthRatio>(segmentCount);
            for (int i = 0; i < segmentCount; i++)
            {
                lengthRatios.Add(new LengthRatio());
            }
            FillInSegmentLengths();
            FillInEndTangents();
            loopCount      = 0;
            remainingLoops = 1;
            traversalTime  = 0.0d;
            speed          = 0;
            completed      = false;
            ratioStep      = lengthRatios[0].ratio;
        }