drawSprites()

Category:Game Lab

Displays a group of sprites. If no parameter is specified, draws all sprites in the sketch.

For an animation, drawSprites is usually used along with background() within draw(). The drawing order is determined by the order the sprites were created, which is stored and can be altered in sprite.depth.

Examples

Spinning Square

Animate a spinning square using the draw loop, background, and drawSprites commands.

// Animate a spinning square using the draw loop, background, and drawSprites commands.
var sprite = createSprite(200,200);
function draw() {
  background("white");
  sprite.rotation = sprite.rotation + 10;
  drawSprites();
}

var sprite = createSprite();
drawSprites();

Syntax

drawSprites(group)

Parameters

NameTypeRequired?Description
group Object The label of the group of sprites to be displayed.

Returns

No return value. Changes output to the display only.

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