window.setTimeout vs Frame Delay Ticking

Recommended Posts

What is the IMPACT in babylonjs of using window.setTimeout and window.setInterval in your babylon js script code logic vs some kins of frame delay tracking flags and check that time has expired in the 'tick' function then execute action function.

Is it 'TABOO' to use browser based timeout and interval functions in your babylonjs game logic 

Is it preferred to use window.requestAnimationFrame game loop (TICKING) to execute DELAYED or INTERVALED functions ???

As Always... Thanks for any info :)


Share this post

Link to post
Share on other sites

I try to avoid setInterval, but it's more a personal preference than anything taboo.

setInterval doesn't report errors or guarantee execution (I didn't know it was CPU load, but thought it was duration of function).  setTimeout calling setTimeout (ie: tail recursion) is considered better by some.  Here is a setInterval npm using requestAnimationFrame:

WHY you are using setInterval is also important.  If you are using it to trigger an action every x ms that seems OK.  I would say that if you are using setInterval only to check for a condition in a loop, progressing a game loop, or sequencing of events/actions that continuation passing style (CPS) or Promises may be better (like onComplete callback for animations) and will react faster.  For really convoluted chaining I may use something like redux-saga (great for game loops) with testable code from the generator functions, even if you skip the redux reducers.  Both CPS and generators can get hard to fathom, but we also have Promises or RxJS!  Probably more than you wanted to hear...

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.