phaser icon indicating copy to clipboard operation
phaser copied to clipboard

"Trim" frame property not properly applied when cropping Sprite that's using an Atlas

Open orcomarcio opened this issue 10 months ago • 1 comments

Version

  • Phaser Version: 3.60
  • Operating system: Window 11
  • Browser: Chrome

Description

Cropping a trimmed sprite seems to not work appropriately. The frame I'm using belongs to an atlas, in case that matters.

Without crop: image

With sprite.setCrop(0, 0, sprite.width, sprite.height) image

Example Test Code

this is wat happen if I use the following codes:

sprite.setCrop(0, 0, 100, 100) image

sprite.setCrop(0, 0, sprite.width, sprite.height) or sprite.setCrop(0, 0, 100000, 100000); (to make sure I'm not being short with w and h) image

A noteworthy thing is that, in this case, the trim is a 11 and the crop changes only below width - trim*2, meaning that with sprite.setCrop(0, 0, sprite.width, sprite.height) and sprite.setCrop(0, 0, sprite.width-22, sprite.height-22) I don't se changes, but below sprite.setCrop(0, 0, sprite.width-23, sprite.height-23) I start to see changes in the trimming.

These are this partucalr trim values if i do sprite.setCrop(0, 0, sprite.width, sprite.height) image

This is the frame config in the atlas.json image

Additional Information

orcomarcio avatar Aug 21 '23 12:08 orcomarcio

This is the correct behaviour, although it's probably worth adding to the docs. Cropping just lets you set the UV coordinates of the texture. So if the texture has been trimmed, you're working from those coordinates, not the sprite size, as that's outside of the UV coords. All it really lets you do is make the UV coords smaller than the defaults.

photonstorm avatar Aug 28 '23 15:08 photonstorm