HTML and CSS Reference
In-Depth Information
Classified intel
The Tile funcion takes four parameters. We want to deine only the required element
parameter; the rest are opional with a default value of zero:
function Tile(element, type, x, y){}
In the current version of JavaScript, we cannot set the default value of the missing
parameters directly in the funcion deiniion.
We need to check whether the parameter is undefined and then assign a default value to
the undefined ones. This can be done with the following statement:
this.x = x || 0;
We have been using the || operator in our code. Now, we take a closer look at it.
The || operator is an OR operator. In most of the languages, it returns a true or false
value. JavaScript returns the first non-false and non-undefined value; otherwise, it returns
a false value. Some examples on what JavaScript returns are given as follows:
return true || "HTML5"; // return true
return "HTML5" || true; // return "HTML5"
return x || 0; // return x if x is not undefined, otherwise it returns
Using a game loop
In the previous secion, we placed the iles in HTML directly, and then moved the temporary
code for the creaion of iles from HTML to JavaScript.
Although the iles are created programmaically, it is a one-ime creaion only. The iles do
not move. No new iles are created ater the iniializaion.
What we will do in this task is coninuously create iles based on a predeined patern,
and keep moving the exising iles down.
Prepare for lift off
In this task, we are going to create iles based on the data provided by the user instead of
having the ile paterns hardcoded.
Before we start, let's remove the temporary code that creates tesing iles in JavaScript.
The startOver funcion is reverted to the following state:
gameScene.startOver = function() {
Search WWH ::

Custom Search