1 decade ago
by paulh
Hi all
another noob question im afraid, but ive created a font with dominics font tool and can display the numbers and letters whats the best way of doing a countdown in minutes:seconds so that game actions can add time to the timer?
I've been looking at online tutorials but here using date function not sure if that's the best approach for ios/impact?
many thanks in advance
Maybe this thread can help. It's not specific to using fonts but its all the same idea.
http://impactjs.com/forums/help/how-to-do-a-countdown
1 decade ago
by paulh
woot, i love it when i get something working (even if its simple) ..
Time = ig.Game.extend({
font: new ig.Font( 'media/white.png' ),//font
secTimer: null,
}
init: function() {
this.secTimer = new ig.Timer(1);// second counter initialise
}
draw: function() {// Draw all entities and BackgroundMaps
this.parent();
this.font.draw( ig.game.min, 416, 2 ); //draw minutes
this.font.draw( ':', 435, 0 ); // draw the seperator
this.font.draw( ig.game.sec, 444, 2 ); // draw the seconds
},
run:function(){
if(this.secTimer.delta() >0){ // when timer has ticked for a second
ig.game.sec ++; // update the global game second counter
console.log("one second"); // log to show its ticking
this.secTimer.reset() // reset it every second
if (ig.game.sec==60){ // if seconds = 60
ig.game.sec=0; //reset the seconds
ig.game.min ++; //add one to the minutes
}
}
If anyone has any comments id love to hear how to do it better!
1 decade ago
by paulh
and this is a countdown timer which stops when it reaches zero .. is this even a reasonable way of doing this?
run:function(){
// always count in seconds.
//if seconds = 0 deduct 1 from minutes
//max value for seconds is 60
if (this.secTimer != null){
if(this.secTimer.delta() >0 ){ // when timer has ticked for a second
ig.game.sec --; // update the global game second counter
this.secTimer.reset() // reset it every second
}
if (ig.game.min ==0 && ig.game.sec ==0){ //if both mins and secs = 0 kill timer
this.secTimer=null;
console.log("gameover");
}
else if (ig.game.sec==0){ // if seconds = 0 //otherwise decrease mins and secs
ig.game.sec=59; //reset the seconds
ig.game.min --; // removes one from the minutes
}
}
this.update();
this.draw();
}
Page 1 of 1
« first
« previous
next ›
last »