Clockwise rotation in degrees of the sprite.
A positive value will rotate clockwise, a negative value will rotate counterclockwise. The rotation usually will be a number between -360 and 360.
The default rotation is 0, which is in the positive x direction. All sprite properties can be both accessed and updated.
Use polar coordinates and sprite.rotation to make an airplane perform loops.
// Use polar coordinates and sprite.rotation to make an airplane perform loops. var startx=200, starty=200, angle=0, increment=10, radius=150; var sprite = createSprite(startx, starty); sprite.setAnimation("planeRed1_1"); sprite.mirrorX(-1); function draw() { background("white"); angle=angle+increment; sprite.x=startx+radius*Math.cos(angle * Math.PI/180); sprite.y=starty+radius*Math.sin(angle * Math.PI/180); sprite.rotation=60-angle; drawSprites(); }
var sprite = createSprite(200, 200); sprite.setAnimation("car_blue_1"); drawSprites(); sprite.rotation = 45; drawSprites();
Use slight random rotations to make a car skid.
// Use slight random rotations to make a car skid. var sprite = createSprite(0, 200); sprite.setAnimation("car_blue_1"); function draw() { background("white"); sprite.x = sprite.x + 5; sprite.rotation = 90 + randomNumber(-3, 3); drawSprites(); }
sprite.rotation
Clockwise rotation in degrees of the sprite.
getDirection
instead.drawSprites()
is called.Found a bug in the documentation? Let us know at documentation@code.org