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