Book Image

HTML5 Game Development by Example: Beginner's Guide

By : Seng Hin Mak
Book Image

HTML5 Game Development by Example: Beginner's Guide

By: Seng Hin Mak

Overview of this book

Table of Contents (18 chapters)
HTML5 Game Development by Example Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
9
Building a Physics Car Game with Box2D and Canvas
Index

Time for action – showing the connection count in a WebSocket application


Carry out the following steps:

  1. Create a new directory named client.

  2. Create an HTML file named index.html in the client folder.

  3. Now, add a few markups in our HTML file. To do this, put the following code in the index.html file:

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>WebSockets demo for HTML5 Games Development: A Beginner's Guide</title>
    </head>
    <body>
      <!-- game elements goes here later -->
      <script src="js/jquery-2.1.3.min.js"></script>
      <script src="js/html5games.websocket.js"></script>
    </body>
    </html>
  4. Create a directory named js and put the jQuery JavaScript file inside it.

  5. Create a new file named html5games.websockets.js as follows:

    var websocketGame = {
    }
    // init script when the DOM is ready.
    $(function(){
      // check if existence of WebSockets in browser
      if (window["WebSocket"]) {
      
        /...