Jump to content

Pausing execution...


Recommended Posts

What's the most elegant way of pausing a BabylonJS animation or game?


I've got gameStateLive which I was going to set to true or false depending..  and I know you can have gameState for instance with various states as well...   So Live, Paused, GameOver, Start etc...  


Is it just to intercept this in the render and pre-render loops or something else?  I need a way to pause and un-pause the javascript and BabylonJS it calls.



Link to comment
Share on other sites

Interesting, I hadn't considered them separately...

I'd quite like the whole game to be paused - everything - so that a player can 'continue' from where they stopped after watching a rewarded advert for instance.  In my mind they have lost all their 'lives' and can 'go again' from that point, with their score intact and progress by watching a rewarded advert and then getting 3 more lives for instance.


Although saying that I quite like the idea of pausing the animations separately as well...!  It's not something I'd considered particularly, but could be used in specific situations.

For me the key item is being able to pause and un-pause the game.  If I can add some differentiation at a later point that would be great but is not essential.  I'm working on a 'list' of must-have elements vs. nice -to-have...  and trying to prioritise them accordingly, otherwise nothing would get completed!

Link to comment
Share on other sites

3 hours ago, Deltakosh said:

So to pause / unpause the best option is just to call engine.stopRenderLoop() to pause the rendering and  then call runRenderLoop to unpause (example: https://www.babylonjs-playground.com/#3A2PUF#5)

For animations, it is even easier, just call scene.animationsEnabled = false



stopRenderLoop - of course!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...