sprite.getScaledWidth()

Category:Sprites

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

The scaled width of the sprite.

Tips

Found a bug in the documentation? Let us know at documentation@code.org