sprite.rotationSpeed

Category:Sprites

Clockwise rotation change in degrees per frame of the sprite.

A positive value will rotate clockwise, a negative value will rotate counterclockwise. Must be used with the draw() function containing a drawSprites().

The default rotationSpeed is 0. All sprite properties can be both accessed and updated.

Examples

var sprite = createSprite(200, 200);
sprite.rotationSpeed=10;
function draw() {
  background("white");
  drawSprites();
}

Faster and Faster

Make the sprite spin faster and faster when the mouse moves.

// Make the sprite spin faster and faster when the mouse moves.
var sprite = createSprite(200, 200);
function draw() {
  background("white");
  if (mouseDidMove()) sprite.rotationSpeed=sprite.rotationSpeed+1;
  drawSprites();
}

Syntax

sprite.rotationSpeed

Returns

The clockwise rotation speed.

Tips

  • rotationSpeed can be used similarly to using the "counter pattern" on rotation within the draw() function.
  • Changing World.frameRate will affect the rotationSpeed.
  • This is not the sprite's movement direction, see getDirection instead.
  • Slight rotations in either direction make sprites look like they are jiggling or skidding while moving.
  • 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