Workshop › Endless Runner › Step 8 of 19
The runner never really moves forward: the world moves toward it. Obstacles live in a list; every frame each one slides
left by speed pixels, and the ones gone off the left edge are dropped.
```js
let obstacles = []
let speed = 6
for (const o of obstacles) o.x -= speed
obstacles = obstacles.filter((o) => o.x + o.w > 0)
for (const o of obstacles) {
ctx.fillStyle = '#15803d'
ctx.fillRect(o.x, o.y, o.w, o.h)
}
```{ x, y, w, h }.o.x -= speed moves it 6 pixels left each frame.filter keeps only the obstacles whose right edge (x + w) is still on screen.runner, write obstacles and speed.update, move and filter the obstacles.draw, draw them.Skills: Arrays and objects
← Tap to jump Cacti keep coming →