Creating an Actor class for the hero and enemies

Now that we have all the main images set up and ready to go, it's time for the fun part (at least in my opinion) as we bring our virtual world to life with JavaScript and HTML5 canvas. Our first order of business is to create an Actor class which contains properties and methods for both the hero and the bad guys. In other words, both the hero and the bad guys will be instances of the Actor class. The Actor class will be responsible for directing the actors with methods such as moveRight() and moveLeft() , and is also responsible for rendering the actors by animating them with sprite sheets.

How to do it...

Follow these steps to create an Actor class which can be used to instantiate the hero or ...

Get HTML5 Canvas Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.