Pause/resume rendering

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.

Original Post on Discord

by user 615280976855171083

Yes via this.context.isPaused = true

Awesome, thanks !

by user 615280976855171083

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

I can’t find documentation on these. For instance I search “pause” in the search bar but have no result. :open_mouth:

by user 615280976855171083

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 :disappointed_relieved: (+ the search is not great, we need to switch to another solution)

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

by user 615280976855171083

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’)

^ 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

Yeah indeed. Thanks anyway !

by user 615280976855171083

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>

by user 395602247196737546

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

Ah oh, thanks. It was just the first context instance I could get a hold of by guessing type names in the console :smile:

by user 395602247196737546