Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

6. HTML5 Canvas > Replacing DHTML Sprites with Canvas Sprites

Replacing DHTML Sprites with Canvas Sprites

In the section A More Dynamic Sprite Application, we developed a DHTML animated sprite system and used it to create various graphical demonstrations. In Chapter 5, we used the same sprite system to develop a DHTML video game. We made some effort to “hide” the mechanics of drawing the sprites within the DHTMLSprite object in order to make the applications using it more amenable to implementing a different sprite system. Here we will convert one of the demonstrations to use a new CanvasSprite object that takes advantage of the increased performance of the Canvas element.

The New CanvasSprite Object

CanvasSprite is a direct replacement for the DHTMLSprite object. All parameters in the params object passed to it are the same as before, apart from the inclusion of a Canvas context parameter (ctx):


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint