PDA

View Full Version : Best steady framerate?



ArmoredSandwich
January 23rd, 2008, 04:23 PM
Hey all,

What would be the best way to accomplish the best steady framerate. I'm currently using setInterval, and I'm experiencing that the fps goes something like this:

http://www.wonima.demon.nl/other/fps_setInterval.JPG

Instead of a nice, steady, flow of continues 30 fps (what I am trying to achieve here).

What would be a better way and what do you use?

Thx,
ArmoredSandwich AKA ImWithNoob.

Sirisian
January 23rd, 2008, 06:23 PM
I would assume you are doing some CPU intensive in your enter frame. If not it's probably just the natural pattern of flash processing its data. I wouldn't worry about it.

Paste your code. There's another explanation and I believe it's because of what you are doing with the set interval. It's processing at an interval of say ever 4 frames and is causing flash to do catch up because it's CPU intensive. Not sure though.

ArmoredSandwich
January 24th, 2008, 08:53 AM
I would assume you are doing some CPU intensive in your enter frame. If not it's probably just the natural pattern of flash processing its data. I wouldn't worry about it.

Paste your code. There's another explanation and I believe it's because of what you are doing with the set interval. It's processing at an interval of say ever 4 frames and is causing flash to do catch up because it's CPU intensive. Not sure though.



engineInterval = setInterval (loops, "engineLoop", (1000/(_root.wantedFPS)));
stop();


When the game is done I simply clear the interval.

The method engineLoop:


this.clearScreen();
_root.game.gameLoop();
_root.clDel.action();
_root.keyList.listen();
_root.powerIndicator.render(1);
_root.theMouse.loop(); // only loop when try to build!

Clearscreen is used to draw the bitmap to the bitmap you see on screen. The gameLoop loops all objects (tanks, buildings etc). Other stuff is just for input etc.

I switched to the normal onEnterFrame again as that seems to be more steady than the setInterval I'm using now.

Marz
January 24th, 2008, 11:40 AM
There are many posts on this forum set that will describe to you possible ways of trying to throttle your FPS correctly but when it comes down to it, unless you compile a game in an exe and distribute it that way, you will not get the same results of FPS over multiple different browsers and operating platforms unfortunately.

-Z-
January 24th, 2008, 12:03 PM
Nice on the visual, I'm assuming you have the bitmap manipulator inside the frame rate or something?


I would try using Timer's, and EnterFrame as well, this is definatly a good comparison test though, I havn't seen it done yet. I think like movieclip vrs bitmapdata, there may be a way to fake steady fps.

Jerryscript
January 24th, 2008, 02:11 PM
When trying to get a consistent interval, I find better results with this method: clear the original interval, check the amount of time your function took to process, and then set the new interval based on the elapsed time of the function. Example:

desiredRate = 33; // 1000/33=30fps approx, adjust as needed
function doSomething(){
var beginTime = getTimer(); // get the starting time in milliseconds
clearInterval(steadyRate); // clear the interval for resetting later

// function calls to your code here

var timeRemaining = desiredRate - (getTimer() - beginTime); // determine new interval
if(timeRemaining <0 ){ timeRemaining = 1; } // check for negative value
steadyRate = setInterval( doSomething, timeRemaining);
}

var steadyRate = setInterval( doSomething, 1);
This is not limited to any particular way of viewing the SWF file, browser, standalone, etc, it is totally time dependant. The only time you should have issues is if your code takes longer to execute than the desiredRate value, in which case there is no method other than fixing your code that will work.

Sirisian
January 24th, 2008, 03:18 PM
There's no reason really to use timers and such. I mean all of my games run at fixed update. Here this might be able to help you:

http://www.gaffer.org/game-physics/fix-your-timestep/

ArmoredSandwich
January 26th, 2008, 09:45 AM
Thanks all, it's exactly what I'm looking for xD.