For this we make use of the rotate method of our drawing context.
We add these lines of code to just before where we call ctx.drawImage.
(The stuff about "PI" and "180" is because most computer languages express angles in Radians. You may have studied Radians in high school mathematics, or seen mention of it on your calculator. Most people find Degrees more natural, and this calculation converts Degrees to Radians. It lets us express our angles in Degrees.)
Try clicking on the window so it gets focus, then pressing the left or right keys.
What happens?
|