Beispiel #1
0
        /**
         * Call this function to give this object a path to follow.
         * If the path does not have at least one node in it, this function
         * will log a warning message and return.
         *
         * @param	Path		The <code>FlxPath</code> you want this object to follow.
         * @param	Speed		How fast to travel along the path in pixels per second.
         * @param	Mode		Optional, controls the behavior of the object following the path using the path behavior constants.  Can use multiple flags at once, for example PATH_YOYO|PATH_HORIZONTAL_ONLY will make an object move back and forth along the X axis of the path only.
         * @param	AutoRotate	Automatically point the object toward the next node.  Assumes the graphic is pointing upward.  Default behavior is false, or no automatic rotation.
         */
        public void followPath(FlxPath Path, float Speed = 100, uint Mode = PATH_FORWARD, bool AutoRotate = false)
        {
            if (Path.nodes.Count <= 0)
            {
                FlxG.log("WARNING: Paths need at least one node in them to be followed.");
                return;
            }

            path        = Path;
            pathSpeed   = FlxU.abs(Speed);
            _pathMode   = Mode;
            _pathRotate = AutoRotate;

            //get starting node
            if ((_pathMode == PATH_BACKWARD) || (_pathMode == PATH_LOOP_BACKWARD))
            {
                _pathNodeIndex = path.nodes.Count - 1;
                _pathInc       = -1;
            }
            else
            {
                _pathNodeIndex = 0;
                _pathInc       = 1;
            }
        }