Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I make a JavaScript animation play at the same speed on all browsers on all systems?
    primarykey
    data
    text
    <p>I have a function that calculates the next frame in an animation of various objects moving in both X and Y axis [ I call it <code>frameRender()</code> ] and a function that applies that resulting frame to the objects [ I call that <code>frameDisplay()</code> ]. The objects don't just move from point A to B, they move constantly, always receiving new target coords. I use a <code>setInterval()</code> with a <code>1000/frameRate</code> interval but that doesn't seem to work at all as browsers don't have accurate timings.</p> <p>The question is: How can I make sure the animation has a constant frame rate, and will run at the same speed on all browsers, on all systems? I have tried everything and can't seem to get an accurate result even on just different browsers (I test on Firefox and Chrome, Chrome usually displays a lot faster).</p> <p>The result should be: When it plays slow, the animation interval should decrease at first, and then try to skip some frames [ by skipping <code>frameDisplay()</code> ] if it the DOM displays slow, until it plays correctly. When it plays fast, the animation interval should increase, making the animation play at the correct speed.</p> <p>But how do you keep consistency in all of this, since you can't always be sure when the browsers will become slow, or when they will perform fast. For example, if there is huge spike of movements, and we decrease the interval to keep the frame rate steady, and then suddenly most of the moving objects stop or don't move much, it will suddenly perform really fast!</p> <p>Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload