diff --git a/flixel/group/FlxSpriteGroup.hx b/flixel/group/FlxSpriteGroup.hx index 94b40b1737..47a3016ca0 100644 --- a/flixel/group/FlxSpriteGroup.hx +++ b/flixel/group/FlxSpriteGroup.hx @@ -59,6 +59,21 @@ class FlxTypedSpriteGroup extends FlxSprite * @since 4.5.0 */ public var directAlpha:Bool = false; + + /** + * Whether getters like findMinX, width and height will only count sprites with exist = true. + * Defaults to false for backwards compatibility. + * + * @since 5.3.0 + */ + public var checkExistsInBounds:Bool = false; + + /** + * Whether getters like findMinX, width and height will only count visible sprites. + * + * @since 5.3.0 + */ + public var checkVisibleInBounds:Bool = false; /** * The maximum capacity of this group. Default is `0`, meaning no max capacity, and the group can just grow. @@ -839,6 +854,13 @@ class FlxTypedSpriteGroup extends FlxSprite return findMaxXHelper() - findMinXHelper(); } + inline function ignoreBounds(sprite:Null) + { + return sprite == null + || (checkExistsInBounds && !sprite.exists) + || (checkVisibleInBounds && !sprite.visible); + } + /** * Returns the left-most position of the left-most member. * If there are no members, x is returned. @@ -855,7 +877,7 @@ class FlxTypedSpriteGroup extends FlxSprite var value = Math.POSITIVE_INFINITY; for (member in group.members) { - if (member == null) + if (ignoreBounds(member)) continue; var minX:Float; @@ -867,6 +889,7 @@ class FlxTypedSpriteGroup extends FlxSprite if (minX < value) value = minX; } + return value; } @@ -886,7 +909,7 @@ class FlxTypedSpriteGroup extends FlxSprite var value = Math.NEGATIVE_INFINITY; for (member in group.members) { - if (member == null) + if (ignoreBounds(member)) continue; var maxX:Float; @@ -933,7 +956,7 @@ class FlxTypedSpriteGroup extends FlxSprite var value = Math.POSITIVE_INFINITY; for (member in group.members) { - if (member == null) + if (ignoreBounds(member)) continue; var minY:Float; @@ -964,7 +987,7 @@ class FlxTypedSpriteGroup extends FlxSprite var value = Math.NEGATIVE_INFINITY; for (member in group.members) { - if (member == null) + if (ignoreBounds(member)) continue; var maxY:Float;