Learn Create Your Own Split Screen

Next Page

To reset the game, here's what we need to do: This last step sounds hard!

The pipes had started way off to the right of the canvas, and by setting an x-velocity they'd slid themselves over the visible portion of the canvas and off to the left. How to make them go back?!

In coding, frequently the best ideas are the laziest.

The easy way to move all the pipes back is just to erase (blow-away) all the items in the pipes array, and then add them all back. We set the pipes array equal to an empty array, then call add_all_my_pipes, just as we did when the program first loaded.

function reset_game() { bird.y = myCanvas.height / 2; bird.angle= 0; pipes=[]; add_all_my_pipes(); }