Search code examples
javascripthtmlcordovaeaseljscreatejs

Createjs create timer clock for game


Does anyone know the best way to create a timer clock in Createjs please? I know I could do something in html and reference it with the DOMElement, but I have had a bit of a nightmare getting that to work in the past? Basically I need to show a timer in a container so the person playing my game can see how long it has taken them to complete a level - pretty standard stuff.

Even better still, if I could get it to use the font in my bitmap text that would be nice. Any help would be much appreciated!


Solution

  • Just track time in JS, and output it to a BitmapText element.

    var startTime = (new Date()).getTime();
    
    // in your update loop:
    currentTime = (new Date()).getTime();
    var time = Math.floor((currentTime-startTime)/1000);
    myBitmapText.text = time + "s";