Skip to content

Commit

Permalink
add checkExistsInBounds and checkVisibleInBounds
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesisfeline authored Mar 30, 2024
1 parent 53d881d commit a695fb2
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions flixel/group/FlxSpriteGroup.hx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ class FlxTypedSpriteGroup<T:FlxSprite> 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.
Expand Down Expand Up @@ -839,6 +854,13 @@ class FlxTypedSpriteGroup<T:FlxSprite> extends FlxSprite
return findMaxXHelper() - findMinXHelper();
}

inline function ignoreBounds(sprite:Null<FlxSprite>)
{
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.
Expand All @@ -855,7 +877,7 @@ class FlxTypedSpriteGroup<T:FlxSprite> extends FlxSprite
var value = Math.POSITIVE_INFINITY;
for (member in group.members)
{
if (member == null)
if (ignoreBounds(member))
continue;

var minX:Float;
Expand All @@ -867,6 +889,7 @@ class FlxTypedSpriteGroup<T:FlxSprite> extends FlxSprite
if (minX < value)
value = minX;
}

return value;
}

Expand All @@ -886,7 +909,7 @@ class FlxTypedSpriteGroup<T:FlxSprite> extends FlxSprite
var value = Math.NEGATIVE_INFINITY;
for (member in group.members)
{
if (member == null)
if (ignoreBounds(member))
continue;

var maxX:Float;
Expand Down Expand Up @@ -933,7 +956,7 @@ class FlxTypedSpriteGroup<T:FlxSprite> extends FlxSprite
var value = Math.POSITIVE_INFINITY;
for (member in group.members)
{
if (member == null)
if (ignoreBounds(member))
continue;

var minY:Float;
Expand Down Expand Up @@ -964,7 +987,7 @@ class FlxTypedSpriteGroup<T:FlxSprite> extends FlxSprite
var value = Math.NEGATIVE_INFINITY;
for (member in group.members)
{
if (member == null)
if (ignoreBounds(member))
continue;

var maxY:Float;
Expand Down

0 comments on commit a695fb2

Please sign in to comment.