Is there a way to pause a game besides timeScale=0?

Hey,

I would like to pause the game. Is there any chance to pause it without changing timeScale property? Maybe there is some “tricky” (internal) way to pause the engine and all its subsystems?

Hi @Igor,

To pause the renderer you can do the following:

this.app.autoRender = false;

Though to pause executing the scripts’ update method and physics update you need to set timeScale to zero.

In addition to pause any input handlers from firing (e.g. mouse events) you will have to manually handle that e.g. using a global GamePaused variable to avoid executing your callbacks:

this.app.mouse.on('EVENT_MOUSEDOWN', function(){
   if( GamePaused === true) return;

   // logic 
}, this);
1 Like

Thanks @Leonidas!
However, would be great to add the pause feature to the pc.Application class (including methods pause(), resume() and bool property paused) that would internally handle physics, sound, input and scripts systems pausing. IMHO that would be more convenient way to stop or pause the app that just setting it’s timeScale.

What do you think guys? Should we create a feature request for this?

1 Like

It seems a valid feature request to me, I’d say go ahead and submit it.

It may not be trivial to implement since scripts can do all kinds of things that the engine can be unaware of, but still seems worthy to investigate.

In theory, you could prevent the update of the various systems in the engine but I can’t remember how many were event driven and how many are explicitly called by function :thinking:

Off hand, you can stop the systems listening to the update event on the application and readd them later.

Hmm, thinking about it more, there may be event listeners on those systems too to be aware of such as input.

The simplest way to do this and truly pause everything is by overriding this.tick on your app. What I do is store a reference to this.tick on pause and then set it to () => {}.

On resume, I set this.tick back to the old reference and call this.app.tick().

Works like a charm and sends resource consumption down to nearly 0.

Caveat: this still doesn’t pause sounds. For that you’ll want to fire pause and resume events on your app and handle accordingly wherever you’re using sound.

2 Likes