MackeyK24 Posted January 10, 2018 Share Posted January 10, 2018 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 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 10, 2018 Share Posted January 10, 2018 Nope this is not taboo at all Just consider that they are not precise functions so they can be delayed or ignored based on CPU load Quote Link to comment Share on other sites More sharing options...
brianzinn Posted January 11, 2018 Share Posted January 11, 2018 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:https://github.com/nk-components/request-interval/blob/master/index.js 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... Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted January 12, 2018 Share Posted January 12, 2018 why not just use a recursive function with a kick out, that is dependent on the before Or AfterRender binding? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.