How do I create a timer that runs even when game is off??

0 favourites
  • 3 posts
From the Asset Store
Full game Construct 2 and Construct 3 to post on Google Play
  • Please, can someone help.I want to create a countdown timer that will run in my game even if the game is off. Then tine continue counting when game resumes.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Here’s the rough idea. You’d need to get the actual time from the system. One way to get that is with the JavaScript Date.now() which gives the number of milliseconds from some fixed date.

    Here I specified that clicking a button will make the timer last 5 seconds.

    Then you can do a comparison to see if the timer has passed the endtime.

    All that’s left is to save and load the endtime to local storage when the game starts and closes. You’ll have to consult some docs how that’s done as I haven’t messed with it in a while.

    var endtime = 0
    
    On start of layout
    — set endtime to webstorage.at(“endtime”)
    
    On button clicked
    — set endtime to browser.execjs(“Date.now()”)/1000+5
    
    endtime >= browser.execjs(“Date.now()”)/1000
    Trigger once
    — do something
    
    On end of layout
    — web storage save endtime to key “endtime”
  • Thanks,am still trying to figure it.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)