Jiri Jiri - 6 months ago 102x
Javascript Question

Change frame rate in paper.js

In Paper.js, is it possible to change the frame rate of the

function? The paper.js website tutorial says the function is by default called 60 times per second, but it does not include if it is possible (and how) to change the frame rate of this function.


No but you can easily skip frames in the code within your onFrame function.

The following code emulates a 30 fps framerate by skipping frames with an odd number, effectively halving the framerate.

var count = 0; // the number of times the frame event was fired:
function onFrame(event) {
    if (count%2===0){

       //your code here



Keep in mind that onFrame is:

  • A better substitute for setInterval
  • You can just use setInterval and set your own frame rate
  • Although onFrame() has some extra advantages:

    • It's a Paper.js designated mechanism
    • It's easier to manipulate and play around within Paper.js
    • It's also more accurate when it actually uses requestAnimationFrame().

There was a discussion about reducing framerates in the mailing list, but it's kind of outdated.