0

Possible Duplicate:
Text blinking jQuery

I'm trying to create a timer in my HTML5/JavaScript game when the game is over. Something like 3...2...1.. where 3 will appear then flash, then 2, then flash, then 1, then flash and return back to my title screen... Nothing I put will get that to work... Anybody able to help me out here? So far my code for the numbers is this:

function CreateTimer(){
    timer =  setInterval(function() {
    cntxt.fillText(time, c.width/2 - cntxt.measureText(time).width/2, c.height/4);
    time--;
    }, 1000);

}

function resetTimer(){
clearInterval(timer);
time = 3;
where = "menu";
}

But even this will just place the 2nd number and then 3rd number straight over the previous and then return the title as expected.

Thanks in advanced!

Community
  • 1
  • 1
D34thSt4lker
  • 447
  • 1
  • 5
  • 12

1 Answers1

0

You need to clear the text first see http://www.w3schools.com/html5/canvas_clearrect.asp

MichaelT
  • 7,574
  • 8
  • 34
  • 47
  • Yes, I have tried doing that but I guess I'm not doing it right because adding the clearRect is just clearing it but not retyping the text once the interval is called again. – D34thSt4lker Sep 09 '12 at 18:50
  • You need to clear it just before you draw another text put it just above cntxt.fillText – MichaelT Sep 09 '12 at 18:54