sprite.getScaledWidth()
The scaled width of the sprite's current image in pixels. If no image or animation are set, it’s the scaled width of the placeholder rectangle.
The sprite.scale
property can be used to scale a sprite larger or smaller and keep the height to width ratio constant. For some games or animations you may need to know the actual width of the scaled sprite in pixels.
Examples
var sprite = createSprite(200, 200);
sprite.scale=2;
drawSprites();
console.log(sprite.width);
console.log(sprite.height);
console.log(sprite.getScaledWidth());
console.log(sprite.getScaledHeight());
Syntax
sprite.getScaledWidth()
Returns
Tips
- If sprite is scaled,
sprite.width
andsprite.height
are not changed. Usesprite.getScaledWidth()
andsprite.getScaledHeight()
instead. - If
setCollider()
is called for a sprite before it is scaled, the collider is not scaled. But if a sprite is first scaled and then the collider set, the scale is also applied to the collider.
Found a bug in the documentation? Let us know at support@code.org.