Let's continue with our previous code. Open the
html5games.untangle.js
file.We need a function to clear all the drawings in the Canvas. Add the following function to the end of the
untangle.drawing.js
file:untangleGame.clear = function() { var ctx = untangleGame.ctx; ctx.clearRect(0,0,ctx.canvas.width,ctx.canvas.height); };
We also need two more functions that draw all known circles and lines. Append the following code to the
untangle.drawing.js
file:untangleGame.drawAllLines = function(){ // draw all remembered lines for(var i=0;i<untangleGame.lines.length;i++) { var line = untangleGame.lines[i]; var startPoint = line.startPoint; var endPoint = line.endPoint; var thickness = line.thickness; untangleGame.drawLine(startPoint.x, startPoint.y, endPoint.x, endPoint.y, thickness); } }; untangleGame.drawAllCircles = function() { // draw all remembered circles for(var i=0;i<untangleGame.circles.length...
HTML5 Game Development by Example: Beginner's Guide
By :
HTML5 Game Development by Example: Beginner's Guide
By:
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
Free Chapter
Introducing HTML5 Games
Getting Started with DOM-based Game Development
Building a Card-matching Game in CSS3
Building the Untangle Game with Canvas and the Drawing API
Building a Canvas Game's Masterclass
Adding Sound Effects to Your Games
Saving the Game's Progress
Building a Multiplayer Draw-and-Guess Game with WebSockets
Building a Physics Car Game with Box2D and Canvas
Deploying HTML5 Games
Pop Quiz Answers
Index
Customer Reviews