Search code examples
javascripthtmlblink

Create blinking "text" in javascript


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!


Solution

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