You are reading a single comment by @allObjects and its replies. Click here to read the full conversation.
  • Since setTimout() holds execution off until timeout happens, it is not working. But your question goes in the right direction:

    1. hold on to current time before invoking nextFrame() (assuming nextFrame() is the 'next' animation step)
    2. invoke nextFrame()
    3. on return from nextFrame() invocation, take time again and calculate you 'new' timeout. If it is negative - your nextFrame() execution took 'too logng' - set timeout to 0. (If you want to - smoothly - catch up with time you may keep late information and include it in subsequent calculations.)
    4. (self)invoke tick(); in setTimout() with calculated timeout.

    This works well if you do not have asynchronous stuff in you nextFrame(). But if you have, it is a bit more complex and you have to figure out a way of chaining within the callbacks. With a chaining approach you get the things most speedy done. Again, this has caveats: if you have only one thing going... if you have multiple asynchronous things going on that can end in different sequence than invocation sequence, you have to pass a shared control object to nextFrame(ctrl) and within that to every callback. In the callbacks the last operation is told about the current, particular completion, and the callback object knows if all has completed to invoke the next tick(). The control object resets itself before invoking tick() with setTimeout() and calculated timeout.

About

Avatar for allObjects @allObjects started