Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix issue #158 - FlxObject doesn't actually stop at the end of its path

The FlxObject following a path will continue to move even if they run
out of path. ( see Issue #158 )
AdamAtomic/flixel#158

This fix adds a "StopWhenFinished" option to "FlxObject::followPath",
as well as some minor changes to avoid repetitious code.
  • Loading branch information...
commit 55a74ecefd19f64b9ad9b4606df0358c339a57c8 1 parent 8989e50
Andreas Renberg authored September 14, 2012

Showing 1 changed file with 18 additions and 5 deletions. Show diff stats Hide diff stats

  1. 23  org/flixel/FlxObject.as
23  org/flixel/FlxObject.as
@@ -254,9 +254,13 @@ package org.flixel
254 254
 		 */
255 255
 		protected var _pathInc:int;
256 256
 		/**
257  
-		 * Internal flag for whether hte object's angle should be adjusted to the path angle during path follow behavior.
  257
+		 * Internal flag for whether the object's angle should be adjusted to the path angle during path follow behavior.
258 258
 		 */
259 259
 		protected var _pathRotate:Boolean;
  260
+		/**
  261
+		 * Internal flag for whether the object's should stop once it has reached the end of the path.
  262
+		 */
  263
+		protected var _pathAutoStop:Boolean;
260 264
 		
261 265
 		/**
262 266
 		 * Instantiates a <code>FlxObject</code>.
@@ -474,8 +478,9 @@ package org.flixel
474 478
 		 * @param	Speed		How fast to travel along the path in pixels per second.
475 479
 		 * @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.
476 480
 		 * @param	AutoRotate	Automatically point the object toward the next node.  Assumes the graphic is pointing upward.  Default behavior is false, or no automatic rotation.
  481
+		 * @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.
477 482
 		 */
478  
-		public function followPath(Path:FlxPath,Speed:Number=100,Mode:uint=PATH_FORWARD,AutoRotate:Boolean=false):void
  483
+		public function followPath(Path:FlxPath,Speed:Number=100,Mode:uint=PATH_FORWARD,AutoRotate:Boolean=false,StopWhenFinished:Boolean=false):void
479 484
 		{
480 485
 			if(Path.nodes.length <= 0)
481 486
 			{
@@ -487,6 +492,7 @@ package org.flixel
487 492
 			pathSpeed = FlxU.abs(Speed);
488 493
 			_pathMode = Mode;
489 494
 			_pathRotate = AutoRotate;
  495
+			_pathAutoStop = StopWhenFinished;
490 496
 			
491 497
 			//get starting node
492 498
 			if((_pathMode == PATH_BACKWARD) || (_pathMode == PATH_LOOP_BACKWARD))
@@ -506,9 +512,16 @@ package org.flixel
506 512
 		 * 
507 513
 		 * @param	DestroyPath		Tells this function whether to call destroy on the path object.  Default value is false.
508 514
 		 */
509  
-		public function stopFollowingPath(DestroyPath:Boolean=false):void
  515
+		public function stopFollowingPath(DestroyPath:Boolean=false, StopMoving:Boolean=false):void
510 516
 		{
511 517
 			pathSpeed = 0;
  518
+			
  519
+			if (StopMoving)
  520
+			{
  521
+				velocity.x = 0;
  522
+				velocity.y = 0;
  523
+			}
  524
+			
512 525
 			if(DestroyPath && (path != null))
513 526
 			{
514 527
 				path.destroy();
@@ -542,7 +555,7 @@ package org.flixel
542 555
 				if(_pathNodeIndex < 0)
543 556
 				{
544 557
 					_pathNodeIndex = 0;
545  
-					pathSpeed = 0;
  558
+					stopFollowingPath(false, _pathAutoStop);
546 559
 				}
547 560
 			}
548 561
 			else if((_pathMode & PATH_LOOP_FORWARD) > 0)
@@ -586,7 +599,7 @@ package org.flixel
586 599
 				if(_pathNodeIndex >= path.nodes.length)
587 600
 				{
588 601
 					_pathNodeIndex = path.nodes.length-1;
589  
-					pathSpeed = 0;
  602
+					stopFollowingPath(false, _pathAutoStop);
590 603
 				}
591 604
 			}
592 605
 

0 notes on commit 55a74ec

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