diff --git a/flixel/group/FlxSpriteGroup.hx b/flixel/group/FlxSpriteGroup.hx index b6fcf43515..527f2dfc5e 100644 --- a/flixel/group/FlxSpriteGroup.hx +++ b/flixel/group/FlxSpriteGroup.hx @@ -47,6 +47,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. @@ -820,6 +835,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. @@ -836,7 +858,7 @@ class FlxTypedSpriteGroup extends FlxSprite var value = Math.POSITIVE_INFINITY; for (member in _sprites) { - if (member == null) + if (ignoreBounds(member)) continue; var minX:Float; @@ -848,6 +870,7 @@ class FlxTypedSpriteGroup extends FlxSprite if (minX < value) value = minX; } + return value; } @@ -867,7 +890,7 @@ class FlxTypedSpriteGroup extends FlxSprite var value = Math.NEGATIVE_INFINITY; for (member in _sprites) { - if (member == null) + if (ignoreBounds(member)) continue; var maxX:Float; @@ -914,7 +937,7 @@ class FlxTypedSpriteGroup extends FlxSprite var value = Math.POSITIVE_INFINITY; for (member in _sprites) { - if (member == null) + if (ignoreBounds(member)) continue; var minY:Float; @@ -945,7 +968,7 @@ class FlxTypedSpriteGroup extends FlxSprite var value = Math.NEGATIVE_INFINITY; for (member in _sprites) { - if (member == null) + if (ignoreBounds(member)) continue; var maxY:Float;