Workshop › Pinball › Step 7 of 42
Every frame the ball moves by its velocity: vx pixels sideways, vy pixels down. That is update, called by the
loop before draw.
```js
function update() {
ball.x += ball.vx
ball.y += ball.vy
}
function loop() {
update()
draw()
requestAnimationFrame(loop)
}
```ball.x += ball.vx adds the sideways speed to the position; ball.y += ball.vy the downward speed.update above function draw() {, with an empty line between them.loop, call update() above draw().Skills: Velocity and gravity, The game loop
← Draw the ball Launch with Space →