flixel
flixel copied to clipboard
FlxSprite.pixelsOverlapPoint and FlxSprite.scale interaction
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
Hey! Thank you for reminding me about this issue. I'll try to implement my solution with rotation support also
Has this ever been addressed since?
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 ^^
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));
Just ran into this issue today. The related issue with FlxMouseEventManagers was marked as intended behavior - is that the case here as well?
I believe this pr should fix that, I just haven't gotten around to testing it