From 5b9fa732cd18e0587ade4823d566b31ac29b39e9 Mon Sep 17 00:00:00 2001 From: George ZenBook Date: Wed, 22 Feb 2023 10:25:26 -0600 Subject: [PATCH 1/3] add checkExistsInBounds and checkVisibleInBounds --- flixel/group/FlxSpriteGroup.hx | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/flixel/group/FlxSpriteGroup.hx b/flixel/group/FlxSpriteGroup.hx index b6fcf43515..24b4ad5671 100644 --- a/flixel/group/FlxSpriteGroup.hx +++ b/flixel/group/FlxSpriteGroup.hx @@ -47,6 +47,17 @@ 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. + */ + public var checkExistsInBounds:Bool = false; + + /** + * Whether getters like findMinX, width and height will only count visible sprites. + */ + 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 +831,13 @@ class FlxTypedSpriteGroup extends FlxSprite return findMaxXHelper() - findMinXHelper(); } + inline function ignoreBounds(sprite:Null) + { + return member == null + || (checkExistsInBounds && !member.exists) + || (checkVisibleInBounds && !member.visible); + } + /** * Returns the left-most position of the left-most member. * If there are no members, x is returned. @@ -836,7 +854,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 +866,7 @@ class FlxTypedSpriteGroup extends FlxSprite if (minX < value) value = minX; } + return value; } @@ -867,7 +886,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 +933,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 +964,7 @@ class FlxTypedSpriteGroup extends FlxSprite var value = Math.NEGATIVE_INFINITY; for (member in _sprites) { - if (member == null) + if (ignoreBounds(member)) continue; var maxY:Float; From f090326d477d0be3fdf2b65bc8c87342dd7610e7 Mon Sep 17 00:00:00 2001 From: George ZenBook Date: Wed, 22 Feb 2023 10:32:57 -0600 Subject: [PATCH 2/3] add since tags --- flixel/group/FlxSpriteGroup.hx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/flixel/group/FlxSpriteGroup.hx b/flixel/group/FlxSpriteGroup.hx index 24b4ad5671..940b77d5dc 100644 --- a/flixel/group/FlxSpriteGroup.hx +++ b/flixel/group/FlxSpriteGroup.hx @@ -51,11 +51,15 @@ class FlxTypedSpriteGroup extends FlxSprite /** * 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; From 6bb3d6a019dc3ce3da7d20890dc22888ee474292 Mon Sep 17 00:00:00 2001 From: George ZenBook Date: Wed, 22 Feb 2023 14:06:22 -0600 Subject: [PATCH 3/3] fix error --- flixel/group/FlxSpriteGroup.hx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flixel/group/FlxSpriteGroup.hx b/flixel/group/FlxSpriteGroup.hx index 940b77d5dc..527f2dfc5e 100644 --- a/flixel/group/FlxSpriteGroup.hx +++ b/flixel/group/FlxSpriteGroup.hx @@ -837,9 +837,9 @@ class FlxTypedSpriteGroup extends FlxSprite inline function ignoreBounds(sprite:Null) { - return member == null - || (checkExistsInBounds && !member.exists) - || (checkVisibleInBounds && !member.visible); + return sprite == null + || (checkExistsInBounds && !sprite.exists) + || (checkVisibleInBounds && !sprite.visible); } /**