Sets the sprite velocity in both the x and y direction.
A positive x parameter will move the sprite to the right, a positive y parameter will move the sprite downward. Must be used with the draw()
function containing a drawSprites()
. You can also update the velocity of a sprite using setSpeedAndDirection()
or by updating the sprite properties velocityX
and velocityY
.
The default velocity is 0 in both x and y directions.
var sprite = createSprite(200, 200); sprite.setVelocity(2,2); function draw() { background("white"); drawSprites(); }
sprite.setVelocity(x, y)
Name | Type | Required? | Description |
---|---|---|---|
x | Number | The velocity of the sprite in the positive x direction, to the right. | |
y | Number | The velocity of the sprite in the positive y direction, downward. |
No return value. Changes output in the display after drawSprites() is called.
World.frameRate
will affect the velocity.Found a bug in the documentation? Let us know at documentation@code.org