Jump to content

game time reset


whiteadi
 Share

Recommended Posts

Changed it like this:

 

...

 

function updateTimer() {
        
        end = new Date()
        diff = end - start
        diff = new Date(diff)
        milliseconds = diff.getMilliseconds()
        seconds = diff.getSeconds()
        minutes = diff.getMinutes()
        var hr = diff.getHours()-1
        if (minutes < 10){
            minutes = "0" + minutes
        }
        if (seconds < 10){
            seconds = "0" + seconds
        }
        if(milliseconds < 10){
            milliseconds = "00" +milliseconds
        }
        else if(milliseconds < 100){
            milliseconds = "0" +milliseconds
        }
 
        timer.setText(minutes + ':'+ seconds + ':' + milliseconds);
        
        if(seconds>time_intervals[level]){
            scoreText.x = game.world.centerX - 200;
            scoreText.font.fill = '#FF0000';
            scoreText.content = 'You lost at level: ' + (level + 1) + '. Score: ' + score + '\nPress SPACE to restart.';
            lost = true;
            resetTimer();
        }
        
    }
    
    function chronoReset(){
        resetTimer();
        timer.content = '00:00:00';  
        start = new Date()
    }
 
...
 
in the create I create a new start date
 
start = new Date()
 
and after that i start the first level and in the update the updateTimer will be called.
 
works ;)
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...