Summary

In the chapter we got started with 2D rendering using the long-awaited canvas API. We looked at the various drawing functions available to us through the canvas rendering context, which includes drawing simple lines and shapes, drawing images from an external image source, pixel manipulation, and image extraction, which allows us to save the image from the canvas back to the user's file system.

We also looked at the new threading system available to us through the web worker interface. This allows us to free up the user interface thread, while we perform long lasting tasks that would otherwise lock up the interface, and cause the browser to display a non-responsive page alert. Unfortunately, there are a few limitations to web workers, since there is no shared memory between workers, and no DOM associated with, or allowed in a worker thread. Still, much can be done with this magnificent new feature of HTML5.

The other HTML5 specific API that we covered in the chapter was the offline application cache. Through this mechanism, we can save specific assets from a web server, storing it as a fast, highly available cache, powered by the user's browser. The specific assets that are saved by the browser are specified by a manifest file, while it is a simple text-based file, and must be served by the server with the text/cache-manifest MIME type.

Finally, we looked at two new additions to the JavaScript language that make game development more efficient and exciting. The first of these two features is requestAnimationFrame, which allows us to render all of our content in a single, synchronized call, managed by the browser itself. This is often the best way possible to render all of our graphics, since the browser can highly optimize the rendering process. The second feature is the typed array data type, which allows for much efficient data storage and access. This is especially attractive to game development because of the extra boost in performance we can get, just by using this new data type, even though it looks and behaves almost 100% the same as regular arrays. Thus, writing new code using typed arrays should include no learning curve whatsoever, as porting existing code that uses arrays is a real treat.

In the next chapter we continue working on the Snake game, making it more robust and feature rich. We'll learn about four more HTML5 APIs, namely sessionStorage, localStorage, IndexedDB, and web messaging.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.50.156