HaxeFlixel / HaxeFlixel/flixel

FlxSprite.pixelsOverlapPoint and FlxSprite.scale interaction

Open
#1,464 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Haxe
Stars
2.2k
Forks
522
Avg merge
34m
Merged PRs (30d)
1

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading FlxSprite.pixelsOverlapPoint(), FlxSprite.scale, FlxSprite.getGraphicMidpoint(), and FlxObject.getMidpoint(), then compare how scaled coordinates are handled. Reproduce the discrepancy with a scaled sprite and pointer position; done means the pixel-overlap and midpoint behavior is consistent with the intended scaling semantics or clearly documented if it is intentional.

Written by the indexing model from the issue text.

Assessment

Domain
computer-graphics, game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.