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

Get help using Construct 2

Post » Mon Oct 19, 2015 11:35 pm

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 8-)
Last edited by Callan S on Wed Oct 21, 2015 3:18 am, edited 1 time in total.
B
52
S
15
G
4
Posts: 191
Reputation: 5,612

Post » Tue Oct 20, 2015 7:22 am

Callan S wrote: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 8-)


This is currently not allowable using C2.

From the Manual:

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.
If your vision so exceeds your ability, then look to something closer.
Moderator
B
136
S
31
G
87
Posts: 5,493
Reputation: 60,272

Post » Tue Oct 20, 2015 8:41 am

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?)
B
52
S
15
G
4
Posts: 191
Reputation: 5,612

Post » Tue Oct 20, 2015 6:10 pm

According to Ashley it's a limit done by the browsers themselves:
game-stops-when-new-tab-is-opened_p850297?#p850297
B
94
S
33
G
114
Posts: 5,359
Reputation: 73,779

Post » Tue Oct 20, 2015 10:35 pm

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?
B
52
S
15
G
4
Posts: 191
Reputation: 5,612

Post » Wed Oct 21, 2015 2:26 am

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
B
94
S
33
G
114
Posts: 5,359
Reputation: 73,779

Post » Wed Oct 21, 2015 3:17 am

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!
B
52
S
15
G
4
Posts: 191
Reputation: 5,612

Post » Wed Oct 21, 2015 3:35 am

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.
B
52
S
15
G
4
Posts: 191
Reputation: 5,612


Return to How do I....?

Who is online

Users browsing this forum: Cubeeo and 21 guests