Skip to content
Browse files

Suggested fix for Issue #158

The FlxObject following a path will continue to move even if they run
out of path.
AdamAtomic#158

This fix adds a "StopWhenFinished" option to "FlxObject::followPath",
as well as some minor changes to avoid repetitious code.
  • Loading branch information...
1 parent 2dd887a commit 6b33fb4eb2707e78f1d3516e73579be053c2c611 @IQAndreas committed
Showing with 18 additions and 5 deletions.
  1. +18 −5 org/flixel/FlxObject.as
View
23 org/flixel/FlxObject.as 100644 → 100755
@@ -254,9 +254,13 @@ package org.flixel
*/
protected var _pathInc:int;
/**
- * Internal flag for whether hte object's angle should be adjusted to the path angle during path follow behavior.
+ * Internal flag for whether the object's angle should be adjusted to the path angle during path follow behavior.
*/
protected var _pathRotate:Boolean;
+ /**
+ * Internal flag for whether the object's should stop once it has reached the end of the path.
+ */
+ protected var _pathAutoStop:Boolean;
/**
* Instantiates a <code>FlxObject</code>.
@@ -474,8 +478,9 @@ package org.flixel
* @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.
+ * @param StopWhenFinished Automatically stop the player from moving once they have reached the final node in the path. Default is "false" just so it won't conflict with code written for previous versions.
*/
- public function followPath(Path:FlxPath,Speed:Number=100,Mode:uint=PATH_FORWARD,AutoRotate:Boolean=false):void
+ public function followPath(Path:FlxPath,Speed:Number=100,Mode:uint=PATH_FORWARD,AutoRotate:Boolean=false,StopWhenFinished:Boolean=false):void
{
if(Path.nodes.length <= 0)
{
@@ -487,6 +492,7 @@ package org.flixel
pathSpeed = FlxU.abs(Speed);
_pathMode = Mode;
_pathRotate = AutoRotate;
+ _pathAutoStop = StopWhenFinished;
//get starting node
if((_pathMode == PATH_BACKWARD) || (_pathMode == PATH_LOOP_BACKWARD))
@@ -506,9 +512,16 @@ package org.flixel
*
* @param DestroyPath Tells this function whether to call destroy on the path object. Default value is false.
*/
- public function stopFollowingPath(DestroyPath:Boolean=false):void
+ public function stopFollowingPath(DestroyPath:Boolean=false,StopMoving:Boolean=false):void
{
pathSpeed = 0;
+
+ if (StopMoving)
+ {
+ velocity.x = 0;
+ velocity.y = 0;
+ }
+
if(DestroyPath && (path != null))
{
path.destroy();
@@ -542,7 +555,7 @@ package org.flixel
if(_pathNodeIndex < 0)
{
_pathNodeIndex = 0;
- pathSpeed = 0;
+ stopFollowingPath(false, _pathAutoStop);
}
}
else if((_pathMode & PATH_LOOP_FORWARD) > 0)
@@ -586,7 +599,7 @@ package org.flixel
if(_pathNodeIndex >= path.nodes.length)
{
_pathNodeIndex = path.nodes.length-1;
- pathSpeed = 0;
+ stopFollowingPath(false, _pathAutoStop);
}
}

0 comments on commit 6b33fb4

Please sign in to comment.
Something went wrong with that request. Please try again.