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 – drawing color circles in the Canvas


  1. First, let's set up the new environment for the example. That is, an HTML file that will contain the canvas element, a jQuery library to help us in JavaScript, a JavaScript file containing the actual drawing logic, and a style sheet:

    index.html
    js/
      js/jquery-2.1.3.js
      js/untangle.js
      js/untangle.drawing.js
      js/untangle.data.js
      js/untangle.input.js
    css/
      css/untangle.css
    images/
  2. Put the following HTML code into the index.html file. It is a basic HTML document containing the canvas element:

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>Drawing Circles in Canvas</title>
      <link rel="stylesheet" href="css/untangle.css">
    </head>
    <body>
      <header>
        <h1>Drawing in Canvas</h1>
      </header>  
      
      <canvas id="game" width="768" height="400">
        This is an interactive game with circles and lines connecting them.
      </canvas&gt...