Browse Source

ObjectFollower : Added autoRemove

TothBenoit 11 months ago
parent
commit
fd4a5f6ea3
1 changed files with 13 additions and 2 deletions
  1. 13 2
      h2d/ObjectFollower.hx

+ 13 - 2
h2d/ObjectFollower.hx

@@ -55,6 +55,11 @@ class ObjectFollower extends Object {
 	**/
 	**/
 	public var cameraRelative : Bool = false;
 	public var cameraRelative : Bool = false;
 
 
+	/**
+		If enabled, the ObjectFollower will remove itself if the object followed is null or removed.
+	**/
+	public var autoRemove : Bool = false;
+
 	var zValue : Float = 0.;
 	var zValue : Float = 0.;
 	var outputScale : Float = 1.;
 	var outputScale : Float = 1.;
 	var tmpPos = new h3d.Vector();
 	var tmpPos = new h3d.Vector();
@@ -71,11 +76,17 @@ class ObjectFollower extends Object {
 	}
 	}
 
 
 	function followObject() {
 	function followObject() {
-		if( follow == null )
+		if( follow == null ) {
+			if ( autoRemove )
+				remove();		
 			return;
 			return;
+		}
 		var scene = @:privateAccess follow.getScene();
 		var scene = @:privateAccess follow.getScene();
-		if( scene == null )
+		if( scene == null ) {
+			if ( autoRemove )
+				remove();
 			return;
 			return;
+		}
 		var s2d = getScene();
 		var s2d = getScene();
 		var width = s2d == null ? h3d.Engine.getCurrent().width : s2d.width;
 		var width = s2d == null ? h3d.Engine.getCurrent().width : s2d.width;
 		var height = s2d == null ? h3d.Engine.getCurrent().height : s2d.height;
 		var height = s2d == null ? h3d.Engine.getCurrent().height : s2d.height;