#Pause/resume rendering

1 messages · Page 1 of 1 (latest)

slow hawk
#

Is there a way to pause/resume the rendering loop ? For instance while browser window is not in focus or simply pausing the game in a menu.

hexed delta
#

Yes via this.context.isPaused = true

slow hawk
#

Awesome, thanks !

hexed delta
#

(this pauses the whole update loop, you can listen to pause changes in scripts via onPausedChanged(newValue, oldValue) too)

slow hawk
#

I can't find documentation on these. For instance I search "pause" in the search bar but have no result. 😮

hexed delta
#

If you're asking to just not call the threejs render method we dont have a bool for that but you could just remove the main camera

#

I think it's not documented right now 😥 (+ the search is not great, we need to switch to another solution)

slow hawk
#

Ahh alright ! An API doc would be awesome in the future indeed. 😉

hexed delta
#

We actually had that for a while but it's not updated autmatically right now so a few versions behind (the reason was that it was re-uploaded too whenever we made a docs change and that took 'too long')

https://engine.needle.tools/docs/api/
^ old api

#

I'm also not sure how useful it is as long as the source code doesnt have more summary comments etc. Personally I wasnt very happy with that yet

slow hawk
#

Yeah indeed. Thanks anyway !

opal storm
#

To auto-pause when the tab/window becomes "hidden" adding this script snippet to the .html seems to works fine in most cases:

<script>document.addEventListener("visibilitychange", () => { Needle.Context.Current.isPaused = document.visibilityState === "hidden"; })</script>
hexed delta
#

Beware that Current can be null depending on when the browser event fires (maybe thats why you say most cases).

You could instead use the NeedleEngine.register... static methods tho to save the context or query the dom element and get the context from it (needleEngineDomElement.context).

Im not sure if the list of all contexts is currently exposed - i have to check that later