phaser
phaser copied to clipboard
"Trim" frame property not properly applied when cropping Sprite that's using an Atlas
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:
With sprite.setCrop(0, 0, sprite.width, sprite.height)
Example Test Code
this is wat happen if I use the following codes:
sprite.setCrop(0, 0, 100, 100)
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)
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)
This is the frame config in the atlas.json
Additional Information
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.