Velocity in the positive x direction of the sprite in pixels per frame.
A positive value will move the sprite to the right, a negative value will move to the left. Must be used with the draw()
function containing a drawSprites()
.
The default velocityX is 0. All sprite properties can be both accessed and updated.
Make a sprite vibrate by alternating velocityX positive and negative.
// Make a sprite vibrate by alternating velocityX positive and negative. var sprite = createSprite(200, 200); sprite.velocityX = 5; sprite.velocityY = 1; function draw() { background("white"); drawSprites(); if (sprite.velocityX>0) { sprite.velocityX = -5; } else { sprite.velocityX = 5; } }
var sprite = createSprite(200, 200); sprite.velocityX = 1; function draw() { background("white"); drawSprites(); }
sprite.velocityX
Velocity in the positive x direction.
sprite.x
within the draw()
function.World.frameRate
will affect the velocityX.drawSprites()
is called.Found a bug in the documentation? Let us know at documentation@code.org