Learn Create Your Own Split Screen

Next Page

The first thing you will have noticed is that after a single keypress, the cat goes crazy.

Remember when we first learned about the canvas, and how changes we make to the drawing context stay in effect until we change them again? For example, if we set the fillStyle to red, everything we draw from that point on will be red.

So it is with rotation, but it's cumulative.

This means even after one key press, the first frame we draw will be rotated 15°, and the next frame will be rotated another 15° (total 30°), and the third frame yet another 15° (total 45°),and so on.

It's because we're calling rotate every time we draw a frame, and the rotates build on each other.