Pause / stop / `noLoop()` p5 sketch when not actively seen by the user (e.g. after scrolling out of window)

Hi everyone,
is there a setting that would automatically pause my sketch when the user cannot currently see it?

For example, I got this blog post here where there’s one sketch at the very top and another sketch at the very bottom of the page. Say I start the top sketch (the agent starts learning) and scroll down (don’t see the top sketch anymore), continue reading and come back up later, the sketch has continued running (as can be seen by some more learning progress).

Now sometimes this is exactly what I want, but sometimes I’d also like the sketch to stop/pause while I’m looking at a different sketch (e.g., for performance reasons, when I have many sketches running on the same page). Is there any way to control this in an easy way?

(When I change tabs, the sketch does pause, as discussed here or there).

Thanks for any hints (also leads to how I can hack this myself if there are no easy / built-in ways). :metal:

1 Like
1 Like