We will continue using our Untangle game. Open the
untangle.drawing.js
JavaScript file in text editor. Add the following code after the Canvas drawing code in thegameloop
function, which draws the current level and progress text inside the Canvas:untangleGame.drawLevelProgress = function() { var ctx = untangleGame.ctx; ctx.font = "26px Arial"; ctx.fillStyle = "WHITE"; ctx.textAlign = "left"; ctx.textBaseline = "bottom"; ctx.fillText("Puzzle "+untangleGame.currentLevel+", Completeness: " + untangleGame.levelProgress + "%", 60, ctx.canvas.height-60); }
Open the
untangle.js
file. We put the following code inside thegameloop
function:untangleGame.drawLevelProgress();
Save the file and preview the
index.html
in a web browser. We will see that the text is now drawn inside the Canvas.
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