Book Image

HTML5 Game Development Hotshot

By : Seng Hin Mak, Makzan Makzan (Mak Seng Hin)
Book Image

HTML5 Game Development Hotshot

By: Seng Hin Mak, Makzan Makzan (Mak Seng Hin)

Overview of this book

Table of Contents (15 chapters)
HTML5 Game Development HOTSHOT
About the Author
About the Reviewers

Choosing a level

In this task, we create a scene that lets the player choose which level they want to play.

Prepare for lift off

We have defined many levels with different types of obstacles. The following figure shows the structure of the LevelSelection symbol:

We also create a ScoreBoard symbol that contains a text field:

Engage thrusters

We have prepared the graphics. Let's work on the code to add the level-choosing logic:

  1. This is something related to the view, so we will put the code in the view.js file. The graphics are already defined and exported. We create the following method to show scoreBoard in the game scene. The scoreboard symbol shows the player's score:

    game.view.showScoreBoard = function(){
      this.scoreBoard = new lib.ScoreBoard();
      this.scoreBoard.x = 10;
      this.scoreBoard.y = 10;
  2. We create the following function to update the text with the latest score:

    game.view.updateScore = function() {
      this.scoreBoard.textField.text = game.score...