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

ignore alpha when point-selecting sprites #3184

Merged
merged 2 commits into from
Jun 12, 2024
Merged
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
33 changes: 30 additions & 3 deletions flixel/system/debug/interaction/Interaction.hx
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,19 @@ class Interaction extends Window
addItemsWithinArea(cast items, members, area);
}

inline function isOverObject(object:FlxObject, area:FlxRect):Bool
{
return area.overlaps(object.getHitbox(FlxRect.weak()));
}

inline function isOverSprite(sprite:FlxSprite, area:FlxRect):Bool
{
// Ignore sprites' alpha when clicking a point
return (area.width <= 1 && area.height <= 1)
? sprite.pixelsOverlapPoint(flixelPointer, 0xEE)
: isOverObject(sprite, area);
}

/**
* Find all items within an area. In order to improve performance and reduce temporary allocations,
* the method has no return, you must pass an array where items will be placed. The method decides
Expand All @@ -703,11 +716,19 @@ class Interaction extends Window

final group = FlxTypedGroup.resolveSelectionGroup(member);
if (group != null)
{
addItemsWithinArea(items, group.members, area);
}
else if (member is FlxSprite)
{
final sprite:FlxSprite = cast member;
if (isOverSprite(sprite, area))
items.push(sprite);
}
else if (member is FlxObject)
{
final object:FlxObject = cast member;
if (area.overlaps(object.getHitbox()))
if (isOverObject(object, area))
items.push(object);
}
}
Expand Down Expand Up @@ -737,10 +758,16 @@ class Interaction extends Window
if (group != null)
return getTopItemWithinArea(group.members, area);

if (member is FlxObject)
if (member is FlxSprite)
{
final sprite:FlxSprite = cast member;
if (isOverSprite(sprite, area))
return sprite;
}
else if (member is FlxObject)
{
final object:FlxObject = cast member;
if (area.overlaps(object.getHitbox()))
if (isOverObject(object, area))
return object;
}
}
Expand Down
Loading