Fit sprite Region to texture in code

Godot Version

Godot 4

Question

This is out there, and to be honest I’m not fully sure if it’s possible. I have a lot of sprites that I need to load into the same position, with their feet in the same position. Problem is that the sprites are centered. The only way I’ve found to make them all consistent is to use regions to resize them, and place accordingly. The problem with that is, once again, I have to individually give them regions.

Is there a way, or is it even possible theoretically to detect where the bottom-most colored pixel on a sprite is and resize a region to that size?

Yes, you can use Image.get_used_rect() to get the non transparent rectangle used in the image. You can get the image with Texture2D.get_image().

Thanks! That worked after mish-mashing the numbers some.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.