sprite.getSpeed()
Category:Sprites
The sprite's scalar speed.
The velocity of the sprite, its speed and direction, can be set in many ways:
- by using the "counter pattern" on
sprite.x
andsprite.y
properties within thedraw()
function - by setting the
sprite.velocityX
andsprite.velocityY
properties - by calling
sprite.setVelocity()
orsprite.setSpeedAndDirection()
Examples
Spiral
Move a sprite in a spiral.
// Move a sprite in a spiral.
var sprite = createSprite(200, 100, 20, 20);
function draw() {
background("white");
drawSprites();
sprite.setSpeedAndDirection(sprite.getSpeed()+0.01,sprite.getDirection()+1);
}
Syntax
sprite.getSpeed()
Returns
The speed of the sprite in pixels per frame..
Found a bug in the documentation? Let us know at support@code.org.