dimanche 31 mai 2015

Stop clock on pause button

I have a "clock" counting down the time of the game (from 9 seconds to 0 seconds). I have a button that pauses the game, so I want to freeze de clock and when I click to play, the game continuos from that second that I frozen. But I don't have any idea how to do this! Can you help me please?

this.addEventListener(Event.ENTER_FRAME, updateTimer);

    function updateTimer(e:Event){
        var t:uint = getTimer();
    var dt:uint = 9000 - t;
    var totseconds:uint = Math.floor(dt/1000);
    var minutes:uint = Math.floor(totseconds/60);
    var seconds:uint = Math.floor(totseconds%60);
    var minsWithZ = minutes < 10 ? "0" + minutes : minutes;
    var secsWithZ = seconds < 10 ? "0" + seconds : seconds;
    var time = minsWithZ + ":" + secsWithZ;
    this.tempo_txt.text = time;

}   

pausa.addEventListener(MouseEvent.MOUSE_UP, menuPause);

function menuPause(e:MouseEvent){
    ...somegame code...
    voltar.addEventListener(MouseEvent.MOUSE_UP, play);
}

function play (e:MouseEvent){
    ...some game code

}

Aucun commentaire:

Enregistrer un commentaire