Discuss Scratch

dimitrip
Scratcher
500+ posts

How to determine sprite costume size and center offset

Hi All.

Handling sprite and clone sizes with the set scale command reveals delicate, specially when you need a relatively good precision.
Of course it's possible to store costume actual sizes in variables or lists, but when you change or update your image and its size changes, an annoying update of the code is then necessary.
Here is a way to automatically determine any sprite or clone's costume size (width and height), and the center offset (offsetx and offsety).

In short, it consists in sizing the sprite until it brushes against the edge to find a gross scale factor, then moving the object up, down, left and right from (0,0) until it also touches the edge. As a bonus you can get that way the image's offset values against the center.

Sequence of graphical is shown for demonstrative purpose, but you can simply hide the sprite's costumes, it works as well.

Greetz.

Dimitri
griffpatch_tutor
Scratcher
28 posts

How to determine sprite costume size and center offset

Very good! If you want to do it even quicker I've devised another method based on a similar idea: https://scratch.mit.edu/projects/110878444/
clowngames11
Scratcher
30 posts

How to determine sprite costume size and center offset

My way of getting costume width (separate sprite)
when green flag clicked
go to [Sprite1 v]
repeat until <not <touching (Sprite1 v) ?>>
move (1) steps
end

Last edited by clowngames11 (July 3, 2024 16:48:35)

Powered by DjangoBB