sprite.width

Category:Sprites

Width of the sprite’s current image in pixels. If no image or animation are set it’s the width of the placeholder rectangle.

The default width is 100. All sprite properties can be both accessed and updated.

Examples

var sprite = createSprite(200,200);
console.log(sprite.width);
sprite.width = 200;
console.log(sprite.width);
drawSprites();

Syntax

sprite.width

Returns

The width of the sprite.

Tips

  • use sprite.scale to resize a sprite and keep the height to width ratio constant.
  • Sprites all have the same properties and you use the dot notation (combining the name of the sprite, followed by a dot, with the label of the property) to both access and update the property for that sprite.
  • Any changes to the properties of a sprite will not be seen until after drawSprites() is called.

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