flixel icon indicating copy to clipboard operation
flixel copied to clipboard

FlxSprite.pixelsOverlapPoint and FlxSprite.scale interaction

Open Aleph0Null opened this issue 9 years ago • 6 comments

After you set a FlxSprite's scale to something other than 1.0, FlxSprite.pixelsOverlapPoint() still behaves as if the image is unscaled, which is unintuitive. Is this intended behaviour?

Currently I'm using this function in a subclass of FlxSprite to check the mouse cursor position against the pixels of the scaled image:

public function isCursorOverPixels():Bool {
    var adjustedx = this.getMidpoint().x + (FlxG.mouse.x - this.getMidpoint().x) / this.scale.x;
    var adjustedy = this.getMidpoint().y + (FlxG.mouse.y - this.getMidpoint().y) / this.scale.y;        
    var adjustedCursorPos = new FlxPoint(adjustedx, adjustedy);
    return pixelsOverlapPoint(adjustedCursorPos);
}

You can replace FlxG.mouse.x and FlxG.mouse.y with other desired coords.

It's also odd that FlxSprite's getGraphicMidpoint() returns the midpoint of the image as if it were unscaled, while the parent object FlxObject's getMidpoint() returns the midpoint of the scaled image

Aleph0Null avatar Apr 04 '15 14:04 Aleph0Null

Hey! Thank you for reminding me about this issue. I'll try to implement my solution with rotation support also

Beeblerox avatar Apr 05 '15 07:04 Beeblerox

Has this ever been addressed since?

TestSubject06 avatar Jul 21 '16 23:07 TestSubject06

Same issue for me when using FlxMouseEventManager.hx who use by default the pixelOverlapPoint() function :] i disable pixel perfect test for the moment. but seems annoying ^^

Breakfasttt avatar Jul 25 '17 20:07 Breakfasttt

This issue is still open and causing issues. There is an additional problem when using offsets, which is that the code needs to account for scaling when doing the offset subtraction. This can be achieved by replacing a line in pixelsOverlapPoint (or a more efficient variation of it):

_point.subtractPoint(new FlxPoint(offset.x/scale.x,offset.y/scale.y));

JackMaher avatar Feb 11 '18 17:02 JackMaher

Just ran into this issue today. The related issue with FlxMouseEventManagers was marked as intended behavior - is that the case here as well?

mpcomplete avatar Apr 05 '22 16:04 mpcomplete

I believe this pr should fix that, I just haven't gotten around to testing it

Geokureli avatar Apr 05 '22 17:04 Geokureli