logo
Search:

Login:


Forgot Details? Sign-up

forum >> Programming questions >> Game Development

simpleGame.js frame rate.

Posted Mar 03 2014 at 1:22 PM by
Thomas Beaner (thomastdb)
I figured it's best to ask this question here. How do I go about changing the frame rate in simpleGame.js? I have read HTML5 game dev for dummies a few times now and can't seem to find it. Also looking through the simpleGame.js code I don't see where the 20 frame limit is? How does this work?
AuthorMessage
Andy
Posted: Mar 26 2014 kl. 1:26 PM

Look under the Scene class start function for a line like this:

this.intID = setInterval(localUpdate, 50);

The 50 parameter indicates the pause (in milliseconds) between calls to the update function. 50 milliseconds is 1/20th of a second so this line sets the frame rate at 20 fps. Just divide 1000 by the intended frame rate to get the number of milliseconds to pause, so set the pause to 33 to get (close to) 30 fps. Make the number smaller for a faster frame rate, and larger for a slower rate.

I actually think 20 fps is a pretty good frame rate for web and mobile games. Experiment if you wish to see if you agree. A higher frame rate doesn't necessary mean better performance. In fact, it's often the opposite. The frame rate is an idealized target, and if your code is too complex, you'll get a lower frame rate no matter what you set the rate to be. Simply asking for a higher frame rate doesn't guarantee it. What we're guaranteed is the frame rate will never go FASTER than 20 fps, which means we'll have a consistent frame rate. That's much better than a game which changes rate based on the complexity of the code. If you set the frame rate too fast for the processor, you'll get an inconsistent frame rate, which is very frustrating to users.

20 fps is still nearly twice as fast as Flash (which defaults to 12 fps) and the engine works fine at this on nearly every device I've tested on. Most humans can't see faster than about 12-15 fps, so we've already exceeded that threshold. (movies run at roughly 24 fps, and TV at about 30, so we're in good company here.)


-Andy