Sprite Width And Height Unaffected By Scale Value?

Hi,

This project shows that a sprite’s width and height are NOT affected by the scale of the sprite. The width and height seem to reflect the ORIGINAL width and height and not the ACTUAL width and height of the scaled sprite.

You can see that I display sprite.width and sprite.height and it does not change when the scale changes.
I also display (sprite.width * sprite.scale) and (sprite.height * sprite.scale), which I reflects the actual size of the sprite.

Is this the way it is supposed to work? The documentation for width and height do not mention this.

John

Hi @jwilson25,

I looked at the documentation for scale and I think this is what you were looking for:
" If sprite is scaled, sprite.width and sprite.height are not changed. Use getScaledWidth() and getScaledHeight() instead."

Does this answer your question - how to access a scaled height and width?
~Michelle

1 Like

Yes! Thank you for double checking me on this. I don’t know how I missed that. Thank you.

Michelle,

I now realize why I missed this. The documentation you found is for the scale property. That’s not a bad place to put it, but I think it should also be in the documentation for the width and height properties as well.

Also, does something have to be included in order to use getScaledWidth() and getScaledHeight()?

To use getScaledWidth() and getScaledHeight(), you just need the sprite name and a . (dot) before the command as per the documentation here.

Hope this helps!

Mike

2 Likes

Thanks, Mike. I didn’t realize it is a sprite property. That makes it clear

John

John Wilson

Computer Science & Math Teacher

Park Slope Collegiate