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

Wrong math in the crop component for trimmed frames #6996

Open
CrispMind opened this issue Dec 26, 2024 · 0 comments
Open

Wrong math in the crop component for trimmed frames #6996

CrispMind opened this issue Dec 26, 2024 · 0 comments

Comments

@CrispMind
Copy link

CrispMind commented Dec 26, 2024

Version

  • Phaser Version: v3.87
  • Operating system: Windows, Android
  • Browser: Chrome

Description

When cropping a trimmed frame, the crop region is cut excessively on the right and bottom.

Example Test Code

// a frame that has transparent area around it and was trimmed from its original size by a texture packer
const image = this.add.image( 0, 0, 'atlas', 'frame' );

image.setCrop( 0, 0, image.width, image.height );

Additional Information

Frame.setCropUVs() has this code:

            //  Need to check for intersection between the cut area and the crop area
            //  If there is none, we set UV to be empty, otherwise set it to be the intersection area

            width = Clamp(width, 0, cw - x);
            height = Clamp(height, 0, ch - y);

But it has a problem as 'cw' and 'ch' are relative to 'cx' and 'cy' respectively while 'x' and 'y' are relative to (0,0) of the untrimmed frame. Not accounting for that leads to the width/height cut off compared to the requested crop region's width/height when cx/cy is not zero. The correct math would therefore be this:

            width = Clamp(width, 0, ss.x + cw - x);
            height = Clamp(height, 0, ss.y + ch - y);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants