Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add checkExistsInBounds and checkVisibleInBounds #2740

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions flixel/group/FlxSpriteGroup.hx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,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 @@ -820,6 +835,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 @@ -836,7 +858,7 @@ class FlxTypedSpriteGroup<T:FlxSprite> extends FlxSprite
var value = Math.POSITIVE_INFINITY;
for (member in _sprites)
{
if (member == null)
if (ignoreBounds(member))
continue;

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

return value;
}

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

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

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

var maxY:Float;
Expand Down