Creating a View class
In this recipe, we'll create the View class, which is the simplest of the three MVC classes. The View class is responsible for drawing state screen images and also renders each animation frame by calling the draw()
method for the level, each of the bad guys, the hero, and the health bar. In addition, the View class also renders a handy FPS display in the top-right cornerof the screen so we can see how well the game is performing.
How to do it...
Follow these steps to create the view for Canvas Hero:
- Define the
View
constructor:/* * Game view * * The view has access to the canvas context * and is responsible for the drawing logic */ function View(controller){ this.controller = controller; this.canvas = controller.anim.getCanvas(); ...
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.