Workshop › Angry Birds-style Slingshot › Step 16 of 47
A bird that flies off the side of the screen would be moved and drawn forever. After each step we keep only the
bodies still near the screen; if the bird is dropped, bird becomes null.
```js
// Fallen off the world: gone.
bodies = bodies.filter((b) => {
if (b.x < canvas.width + 50 && b.x + b.w > -50) return true
if (b === bird) bird = null
return false
})
```filter builds a new array with the items for which the function returns true.return false drops them; if one of them is the flying bird, we forget it.In step, after the for loop's closing }, write the comment and the filter.
Skills: Arrays and objects
← An empty sling in flight Wait for calm →