How do I prevent suspending on unfocused tab?

0 favourites
  • 5 posts
  • Hello Guys!

    If you recall, I'm making a Planet Clicker game, and thought that some people might want to have it up in the background to give them coins even when they need to switch to something else temporarily (like reading an email for example). I saw a post, but it was from 7 years ago, and Construct 2. I was wondering if it is possible to prevent the suspending when you leave the tab or open a different window on top. I saw in the old post that it would run in low frames, which isn't a problem- all it needs to do is add a variable to another variable every .1 seconds, and every 1 second. I would be okay if it pauses the audio (in fact, this would be preferred) or unloads *small* amounts of data, like unused images and stuff too. Does anyone know how to do this? Also, I have the free version of Construct, and only 1 event left ): I've been looking through and trying to optimize stuff.

    Edit: After clearing some extra homemade special icing off the top of Santa's Cookies, I now have around 7 events left, but don't wish to use them all.

    Tagged:

  • all it needs to do is add a variable to another variable every .1 seconds, and every 1 second

    Your game doesn't need to continue running for that. You save the time when the game was suspended. When it's resumed, you simply calculate how much time has passed and add it to the variable. Use Date object to access system time.

  • Okay, that'll work! Thanks a lot! That gave me another great idea to basically add what in Cookie Clicker would be called, "Sugar Lumps" Can you help me use the date to first add in coins since suspension, then I'll learn from that. Also, is it possible to only add them in since suspension, and not since the tab was closed, computer shut down/hibernated, etc? Again, thanks!

  • Try searching the forum for something like "idle income", there are lots of posts.

    Use Date.now expression of the Date plugin to get the system time in milliseconds:

    construct.net/en/make-games/manuals/construct-3/plugin-reference/date

    While the game is running, save the time to Local Storage every several seconds or so. When the game is launched, try to retrieve the value from Local Storage and calculate how much time has passed.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you so much, you've been a great help.

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