5

Is it worth using request animation frame if I am forcing it to go on 25 FPS. This is why I am asking:

Normal RAF behaviour: a1000ms / 60 fps = 16.66a That is a standard refresh rate of most monitors.

Dropping FPS to 30 :

1000 / 30 = 33.33 that is exactly half of 60 and that means that every other RAF execution will do something which is logical and consistent

Dropping FPS to 25 :

1000 / 25 = 40 this is not dividable by 16.66(usual RAF time for screen update)

With this logic, i would have to draw every 40 ms something to the screen, but that is not possible cause one frame is 16.66.

I am lowering the frame count by standard code:

fps = 25,
renderRate = 1000 / fps,
function animation(timestamp) {
    draw.requestAnimationFrame = requestAnimationFrame(animation);
    now = timestamp;
    elapsed = now - then;
    if (elapsed > renderRate) {
        then = now - (elapsed % renderRate);

        //Some code for execution goes here
    }
}
Karl Gjertsen
  • 4,690
  • 8
  • 41
  • 64
iGoogle
  • 136
  • 9
  • Without knowing the total context on the page, there isn't really an answer to this. The refresh rate of the screen doesn't guarantee anything about RAF anyway, the flegmatic aspect is the point of using it - execute as often as the device can handle. Usually you would try to get it as high as possible, meaning the script is written well and not overexposing the CPU. Why would you try to throttle it in this case? – Shikkediel Nov 23 '15 at 13:39
  • I have a 2 x 25 frame images that i need to animate. If i run them with 60 frames, they go too fast, and it misses the point. Lowering it to 25 Fps reduces the size of sprites and application is much lighter. – iGoogle Nov 23 '15 at 13:46
  • If your code is functional, try asking at codereview.stackexchange.com. If it's not, please edit to include a specific problem and question. Thanks. – miken32 Nov 23 '15 at 22:33
  • Generally, keep rAF running a full speed and inside each frame test if `rafArgumentSuppliedTime > startTime + duration`. That way you don't have to anticipate when the next frame will occur (anticipation may fail because the system demands time and rAF may therefore be delayed). – markE Nov 29 '15 at 20:41

0 Answers0