Corners position of the sprite

I am building a text plugin since we are in need of a special design of characters, I decided to extend the plugin and instead of regular Playcanvas text, use sprites.

The problem is I don’t know how to calculate the offset since there is no collider on a sprite, and I can’t use bounds.
Is there any solution to this, to get any corner position on the screen so I can calculate the offset between sprites?

I had an idea for pivot and the width, but unfortunately, the sprite will be scaled during the runtime, so I am not so sure is it the smart idea

Hi @Dava,

I am fairly certain for sprites, and regular text/image elements, you can only get the total image bounding out of the box. The image is rendered on the GPU so you don’t have any other per pixel info from the PlayCanvas engine.

If you would like to get per pixel info / trimmed bounding box you will have to read the pixels for each image and discard all transparent pixels. With a low level method like this:

2 Likes

You could get the frame data from the atlas and calculate the corners via the entity transform. It’s a bit tricky but could be possible :thinking:

1 Like