Get your 25fps flash movie to actually run at 25fps in IE
I posted this in another thread, but thought i'd post it here as well as we see this sort of question now and again.
As some of you may know, if you tell a flash movie to be published at 25fps in flash, when you run it as a standalone flash movie it will pretty much run at that 25fps (unless your computer isnt fast enough)
But..... if you run it through a html page, you get something stupid like 21fps, for no obvious reason other than someone at macromedia/microsoft/mozilla likes monkees.
Anyhow, heres a work around which although works quite well, will only work most accurately if your publishing your movie at a frame rate of between 1 - 12, 13, 15, 17, 20, 25, 34, 50 or 100 (see http://www.flashkit.com/board/showthread.php?t=638974 for a reason as to why)
1. Forget whatever framerate you want your game to run at, and set flash to publish at some stupid rate, 120 is good. (but anything more than 10fps higher than the rate you really want should be fine)
2. Make a blank Movieclip on your main stage that will be there throughout ur entire game
3.Stick this code on the first frame of that new movieclip
starttime = newDate()
var currtime=new Date()
var currtime = new Date()
4. Change the 'DESIREDFRAMERATE' to be whatever you want, though please note, you will only get the frame rates noted above. If you type in a number not in the above list, it will get rounded down. Ie, 30 would give you 25fps.
At first, it ran at a constant 64 fps, which was far too fast to control the car. However, after pressing the 25 fps button, it switched all the way down to 22fps and stayed there the whole time. It seems like a nice idea for getting that ideal framerate, but it looks like not too much of a fix, at least for me. A difference of 1 fps isn't enough (from 21) to make me want to use this in all of my games. However, it was a very cool idea and I'm sure it should work in other instances.
I got 60 fps without, and 22 with the limit. I assume the 3 fps drop is due to the game itself, instead of the code limiting the fps? Come to think of it, how much impact will the code actualy have on the CPU usage? Or is it not to be counted?
For some reason on the 3 machines at work i've tried it on, when i turn on the 'lock to 25fps' it does indeed stay at 25fps (one machine hovers between 24/25)
but after reading this thread this morning, i tested it on my home machine and i also got 22fps
I get 18-20 fps in the gta demo with both settings. Then again, I am not using IE - Tony PA
You need to have a fast enough machine to get more than 25fps on launch to be able to limit it to 25 mr tony
Without limit 13-25% cpu of my 3ghz, and limit on 40% cpu, why would you lower fps and have worse performance?
Nice thought but a lot of AS testing gives more CPU usage so its not worth it. - Erixon
Very very good point!! It seems the while loop just zaps all CPU power. Maybe if i published the movie at 30fps instead of 120, it would be more user friendly. Though from the results of this thread its not consistantly locking to 25fps anyway
André Michelle is testing the code aswell, he's currently put the code into his Super Mario game. http://lab.andre-michelle.com/ (look under the games menu on the left for 'supermario')
On my work machine here I get 33fps. Let him know what you all get
Hmmm.. then what's actualy the use of this code, other then changing the fps on the flow...
You might as well put your fps on 25, it'll be waay less cpu intensive and you still have an fps drop of 3-4.
tis just that on my work machines, the game does run at 25fps.
Which is why i posted the thread.
But it seems I didnt test on enough machines and the work machines are freaky, because as you and others have found out, and now myself aswell on my home machine. On other systems the game runs at 22fps
You can simply use wmode = transparent in your html and it will run at exactly the frame rate you set ( in IE ) unless your CPU is too slow or you have too demanding of a game. But, yes wmode corrects this. A game set to run at 30 fps will run at around 25 without wmode ( no matter how fast you cpu is ), and with wmode it will run at exactly 30 you specified.