I discovered It when I changed the frame rate to 100 in place of 60 or 30, and the game started running at 90-65 fps. This means my browser can easily run It at 60 fps constant.
Here the code I think is wrong:
var nextTickTimeout = 1000/60 - (startTime - (new Date().getTime())); if (nextTickTimeout < 0) nextTickTimeout = 0; if (!quit) setTimeout(gameTick, nextTickTimeout);
And this is the whole function:
function gameTick ()
{
var startTime = new Date().getTime();
date = new Date();
lastTime = currentTime;
currentTime = date.getTime();
deltaTime = currentTime - lastTime;
milliseconds += deltaTime;
// update game objects status
engine.update();
// render graphics
if (frameCount == Math.floor(frameCount / frameSkip) * frameSkip) engine.draw();
// code to measure FPS (Frames per Second)
if (milliseconds >= 1000)
{
fps = frameCount;
// update FPS for this frame
if (fpsElement != null) fpsElement.innerHTML = frameCount + " FPS";
// reset frameCount and milliseconds
frameCount = 0;
milliseconds = milliseconds - Math.floor(milliseconds / 1000) * 1000;
}
frameCount += 1;
var nextTickTimeout = 1000/60 - (startTime - (new Date().getTime()));
if (nextTickTimeout < 0) nextTickTimeout = 0;
if (!quit) setTimeout(gameTick, nextTickTimeout);
}
Maybe is not possible to do It in javascript? I don't know how precise is setTimeout.
This is more of an experiment I'm doing to found out how complex the game can be and still run at least at 30-25 fps in a not so new machine. I will change "nextTickTimeout = 1000/60" for "nextTickTimeout = 1000/30" or 25 if 60 probes to be too much.
I have seen HTML 5 games of comparable complexity to the one I want to make so my game should be possible.






