[Solved] How do I keep a game running even when tabbed away?

0 favourites
  • 8 posts
From the Asset Store
five golem elements Sprites Sheet.Best for enemy or villain game characters.
  • I'm interested in writing an idle game that keeps running even when you're in another tab browsing something else.

    How do I do that? Thanks

  • I'm interested in writing an idle game that keeps running even when you're in another tab browsing something else.

    How do I do that? Thanks

    This is currently not allowable using C2.

    From the Manual:

    [quote:l2c9z31n]Page is visible

    True if the page the HTML5 game is running on is currently visible. The page counts as hidden if the window is minimised, the page is in a different tab to the one being viewed, or on a mobile device when the app goes in to the background. When the page is hidden the game automatically pauses.

  • Really? That puts a real dampner on my investigation of construct. It's not currently what I need (is there some practical requirement to make the program pause at such times?)

  • According to Ashley it's a limit done by the browsers themselves:

  • I don't think Ashley understands the idle game genre, that players of idle games are okay with the game running/continuing to use the battery.

    But that 'wallclocktime' has potential to manage the in between time (thanks for the link, ROJO), even if it complicates things for me as someone new to construct. I guess 'every X seconds' wont be enough for me now...

    Edit: So I've tried to figure out how to access the 'OnSuspended' value to get the time of suspension and I can't quite figure out how to do that? Can anyone point me in the right direction? Rojo?

  • The browser object has that condition. Also I think the wall clock idea is better than letting the game run in the background. If you get the DateTime plugin you can extend the idea to getting money when the game is closed.

    Anyways here's a simple example of an idle game:

    Global number money=0

    Global number moneyPerSec=10

    Global number suspendTime=0

    Every 1.0 seconds

    --- add moneyPerSec to money

    On suspend

    --- set suspendTime to wallClockTime

    On resume

    --- add (wallClockTime-suspendTime)*moneyPerSec to money

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ah, I see - you have to go to the layout and double click to put the browser object into the project. Then you can use it to produce the 'on suspend' conditional. I didn't even think there was a browser object to add (I kind of imagine HTML5 games as always being in browser so I thought the on suspend thing would be built in). Okay, thanks ROJO!

  • Yeah, managed to get it to work (my first code that worked first time around!). It has a bit of a 'race ahead' issue, but I guess if I did not show the display until the update was done then that'd be hidden.

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