Sets the image or animation for the sprite.
Use the Animation tab to load and label images and animations for your sprites.
The default image is a gray rectangle.
var sprite = createSprite(200, 200); sprite.setAnimation("car_blue_1"); drawSprites();
Use 6 different images for a sprite, labeled "dieRed1" through "dieRed6", and randomNumber to roll a die.
// Use 6 different images for a sprite, labeled "dieRed1" through "dieRed6", and randomNumber to roll a die. var die = createSprite(200,200); var count=0; function draw() { background("white"); count=count+1; if (count<20) { die.setAnimation("dieRed"+randomNumber(1,6)); } drawSprites(); }
sprite.setAnimation(label)
Name | Type | Required? | Description |
---|---|---|---|
label | String | The name of an image or animation loaded in the Animation tab. |
No return value. Changes output in the display after drawSprites() is called.
drawSprites()
is called.Found a bug in the documentation? Let us know at documentation@code.org