Patrick H. Lauke works as an accessibility consultant for The Paciello Group. In a previous life he was a web evangelist in the developer relations team at Opera Software ASA, and before that he worked as a web editor for a large UK university for nearly 10 years. Hes been involved in the discourse around web standards and accessibility since 2001, speaking at conferences and actively participating in initiatives such as the Web Standards Project (WaSP). An outspoken accessibility and standards advocate, Patrick favors a pragmatic hands-on approach over purely theoretical, high-level discussions. His personal corner of the Web can be found at http://www.splintered.co.uk/.
Preface
Even among experienced web developers, I often hear the question, What exactly is HTML5? The answer is difficult, in part because the rate of technological advances means the answer may change from one week to the next. The term HTML5 also tends to be used to bundle a collection of techniques, and those techniques are often judged by their end effect rather than the technology that created them.
Because of the uncertainty surrounding the term HTML5, the label of HTML5 game programmer has acquired a mystique, as if moving from web developer to game programmer requires superpowers. Thus the reason for this book: to demystify the transition from building web pages to building web games.
The challenge of writing a book on web technology is that the digital world moves so much faster than the physical one. Fashions and practices change while a book moves from first draft to publication, and technologies advance at such a pace that a book risks being obsolete from the day its published. Thankfully, the path for HTML5 has been laid down by the World Wide Web Consortium (W3C) with the support of the major browser vendors, so my challenge was less about guessing which HTML5 features to include and more about considering when these features might be readily available for mainstream use. I was keen to write a practical how-to guide in the form of a tutorial, with techniques that could be used in the wild from day one, and Im glad that features that were cutting edge when I wrote the initial draft are now supported by most web browsers.
Acknowledgments
Along the way, the input from the No Starch Press team has been invaluable in shaping the contents of this book. Thanks go to Keith Fancher, who initially made contact and suggested I start writing in the first place; Tyler Ortman, who set me on the right path after a very unstructured first draft; Alison Law, who kept the whole process moving along; and especially my editor, Jennifer Griffith-Delgado, without whom this book would have been twice as long and made half as much sense. Id also like to thank my technical reviewer, Patrick Lauke, who was particularly invaluable in identifying areas where technology changed during the time between initial draft and final version.
Im also grateful to a host of former co-workers and bosses who put up withand often even encouragedmy playing with fun effects when I should have been working on paid projects. And finally, Id like to thank my partner, Ann, whose goading about how long it was taking me to finish the book ensured that I didnt give up entirely.
Introduction
Games are everywhere, and theyre increasingly played on connected web devices and within desktop and mobile browser environments. As browser-based games become more popular, players are turning to sites like Facebook to discover simple, casual games that dont require a disc or much up-front setup to play. A game is just another link to click through.
During the past decade, improvements to Adobes Flash plug-in contributed to the growth of the web browser as a gaming platform. Most browsers supported Flash, giving game developers access to a powerful platform that approached the dream of write once, run anywhere . HTML-based games have been around about as long, and you may even have played some (possibly without noticing). However, until recently, the use of HTML and JavaScript as a gaming platform played second fiddle to Flash due to graphics, sound, and speed limitations. But browsers and mobile gaming platforms have vastly improved, and the status quo is changing. Mobile operating systems have steered away from Flash as a supported plug-in, and as a result, game developers need tools that provide similar performance and flexibility while retaining the ubiquity that Flash had.
Browsers have also seen a rapid improvement in graphical and sound capabilities over the past few years. The rise in power of HTML mirrors increasing demand for a platform that delivers rich gaming experiences and has the backing of multiple platform providers. A well-supported, open platform is considered less likely to fall foul of commercial controls and a walled-garden mentality, and HTML5 is such a platform.
However, in my experience, many game developers come to HTML5 looking to build the same type of games they would have built in Flash. HTML5 is certainly one of the best options: it has a huge user base (anyone with a modern web browser), and HTML5 and Flash have many similar capabilities and constraints. Despite this similarity, thinking of HTML5 as a Flash replacement is likely to lead to disappointing product launches and missed opportunities. This is because the strengths of one do not directly map to the strengths of the other. Also, HTML5 is still in a relatively early stage of development. The platform is advancing rapidly, and it can be difficult to keep up with which new features are supported from month to month.
Much as with building a good web application, the key to making a successful game is to understand your platforms capabilities and restrictions. You have to design and build games that maximize the platforms potential while avoiding or minimizing its limitations. This book is intended as a first step in understanding what you can achieve with JavaScript, HTML, and CSS and introducing the methods by which you can do so.
Why Build HTML5 Games?
Before I dive into specifics about this book, lets step back and consider why you might want to create a game on the HTML5 platform in the first place.
Using Skills You Already Have
Web developers who are skilled with JavaScript and CSS will feel more confident about stepping into HTML5 game development. Deploying HTML and JavaScript files is also a familiar process, and you can build online components using server-side languages that overlap with web development.