Shrink or grow a sprite keeping the height to width ratio the same.
For example, a value of 2 will be make the sprite twice as big and a value of 0.5 will make the sprite half as big. Scaling up may make images blurry. The scale should always be a positive number.
The default scale is 1. All sprite properties can be both accessed and updated.
var sprite = createSprite(200, 200); sprite.setAnimation("car_blue_1"); drawSprites(); sprite.scale = 0.5; drawSprites();
Animate three different sized pinwheels.
// Animate three different sized pinwheels. var pinwheel1 = createSprite(randomNumber(0, 400), randomNumber(0, 400)); pinwheel1.setAnimation("Pinwheel.png_1"); pinwheel1.scale = 0.1; var pinwheel2 = createSprite(randomNumber(0, 400), randomNumber(0, 400)); pinwheel2.setAnimation("Pinwheel.png_1"); pinwheel2.scale = 0.2; var pinwheel3 = createSprite(randomNumber(0, 400), randomNumber(0, 400)); pinwheel3.setAnimation("Pinwheel.png_1"); pinwheel3.scale = 0.05; function draw() { background("white"); pinwheel1.rotation=pinwheel1.rotation+10; pinwheel2.rotation=pinwheel2.rotation-30; pinwheel3.rotation=pinwheel3.rotation+50; drawSprites(); }
sprite.scale
The scale of the sprite.
drawSprites()
is called.sprite.width
and sprite.height
are not changed. Use getScaledWidth()
and getScaledHeight()
instead.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 documentation@code.org