As the title says, how do you set a fixed frame rate of 25 fps for PixiJS?
Here is my setup:
JavaScript
x
3
1
g_App = new PIXI.Application(800, 600, { backgroundColor: 0x1099bb });
2
document.getElementById("canvas-div").appendChild(g_App.view);
3
I do not want to do any more frames than that.
Advertisement
Answer
After @wavemode’s comments about PixiJS using requestAnimationFrame I think I may have to do the following. (Note: if there is a better solution, please post it, otherwise I will mark this as the answer.)
Basically, stop any animation if we are exceeding the frame rate.
JavaScript
1
3
1
var g_TICK = 40; // 1000/40 = 25 frames per second
2
var g_Time = 0;
3
Then later on when we set up the animation:
JavaScript
1
19
19
1
// Listen for animate update
2
g_App.ticker.add(function (delta) {
3
// Limit to the frame rate
4
var timeNow = (new Date()).getTime();
5
var timeDiff = timeNow - g_Time;
6
if (timeDiff < g_TICK)
7
return;
8
9
// We are now meeting the frame rate, so reset the last time the animation is done
10
g_Time = timeNow;
11
12
// Now do the animation
13
14
// rotate the container!
15
// use delta to create frame-independent tranform
16
container.rotation -= 0.01 * delta;
17
g_Bunny0.x += 1;
18
});
19