HTML and CSS Reference
In-Depth Information
2. Let's move to the game.js ile to add the imer control to the game low:
gameWin: function() {
...
game.timer.stop();
},
gameOver: function() {
...
game.timer.stop();
},
startLevel: function() {
...
game.timer.restart();
},
3. We remove the following code from the init method in order to prevent the imer
from staring during the menu scene:
var init = function() {
game.flow.startLevel(); <<<<< Delete this line.
}
4. The imer is something that can be reused in other games, so it is worth creaing a
dedicated file named timer.js . Let's put the following imer code into the newly
created timer.js file:
(function(){
var game = this.colorQuestGame = this.colorQuestGame || {};
game.timer = {
interval: undefined,
countFrom: 60, // second
count: this.countFrom,
progressView: document.getElementById('timer'),
restart: function() {
if (this.interval) {
clearInterval(this.interval);
}
this.count = this.countFrom;
this.interval = setInterval((this.tick).bind(this), 1000);
},
stop: function() {
clearInterval(this.interval);
},
tick: function() {
this.count -= 1;
 
Search WWH ::




Custom Search