slowdown on game when uploaded?

13 posts

Flag Post

i’ve just started programming with actionscript, and i uploaded a game (not a complete game mind you, just something i threw together while messing with tutorials to test movement code), yet when i play it it online on kongregate it plays a lot slower then it does when i open the .swf file. do i need to lower my frame rate (it’s 60 fps at the moment) or is there some other reason for this? TIA

Flag Post

60fps seems rather high—I’ve heard several folks here say that 30fps is fairly standard for games.

When you play online the .swf has be to hosted inside a browser, which may cause a speed hit. When you run the swf directly, you’re probably running directly under the Flash Player, which doesn’t have the browser overhead. Try publishing the html on your hard drive and opening it in a browser directly, and see if performance suffers.

Flag Post

As Chalain said, it will run slower in a browser than directly from the player. You should always test your game from within the flash development program by publishing, rather than Test Movie. You can easily do this by pressing F12. This will publish and open your browser at the same time, making it easy to do. It can suck balancing a game to a certain speed in Test Movie when no one will probably ever play it at that speed.

I now only use Test Movie to check to see if things actually work, or to check the layout. But for any speed issues, I will publish.

Flag Post

Also, since Kongregate wraps all of the games in another swf in order to have the chat window, your game may suffer a slight drop in fps when run in this wrapper (though in my experience this drop fluctuates and sometimes seems non-existant).

Flag Post

ah ok, i just tested it using F12 and it plays slowly also, guess i gotta bring the fps down. thanks guys :)

Flag Post

Firefox and IE both limit the amout of resources a Flash applet can use. Safari (at least the Windows Beta) doesn’t seem to have that cap and Flash runs a lot faster in it.

Generally it is a good idea to optimize your game so that it can run even on older hardware. I develop on a 5 year-old laptop, because I’m too cheap to buy a new computer. But it has the upside that I can be pretty sure if it runs ok on my machine, it will run fine for most players.

Flag Post

I uploaded my game Bee Jeez yesterday on Kongregate , Here is the link “”. The game’s FPS is tuned to be around 35fps. The game normally runs well on my comp ( I have tested with F12 ). And it also runs fairly smoother at the other site “Bubblebox” “”. But it lags a lot on kongregate. I tried increasing my fps to even 45 and re-uploaded.. still it is fluctuating a lot between 25 to 40. As mentioned above by “ch00se”. the fluctuation and lagging happens more when the chat window gets refreshed or reloaded. Is there anyway we can get away with this here??


Flag Post

I’ve done a little testing and some searching the net.

This browser slow-down seems to be a recurrent problem.

My current game is supposed to run at 20fps. When in the browser, it is a bit slower. But this isn’t because it is frame-rate limited – if I increase the intended frame rate to 25 fps, it runs at about the same rate as in the test box. This is in-line with previous observations of a 20% reduction in frame-rate. I don’t think I’m doing anything particularly intensive, and putting the frame rate up to 50 or 100 leads to very fast (but increasingly wobbly) action.

After some thinking, my theory is that flash is completely dropping some frames, perhaps due to occasional garbage collection or something like that. It therefore isn’t necessarily about how much stuff you’ve got going on.

But the question is how to mitigate it. The problem isn’t really that it slows things down, it’s that it isn’t guaranteed to do so consistently. Otherwise we could just increase the intended frame-rate.

I think there are three classes of solution – all involve measuring the time between frames.

  1. (1) Set your frame rate to what you can live with. At a fixed point each frame, determine time since the start of the previous frame. Move objects a variable amount dependent on this time.
  2. (2) Set your frame rate to a multiple of what you want. Track the time of each of the last few frames, and only perform a game cycle when a certain amount of time has elapsed since the last one. Carry over any remainer.
  3. (3) Set up an event (using setInterval) to run your game-loop instead of onEnterFrame. Given what it says in its description, I think you’d need to use a multiple of your frame rate, and drop some events. You might still need to track remainder time.

2 and 3 are essentially very similar. 1 may seem more efficient, but it can introduce a lot of complexity, and may cause some new problems.
I don’t know how much of a cost having more frames would be, but if you don’t draw anything in the skipped frames it may not be very much.

Flag Post

Hi Lysis,
Thanks a lot for the comments.

I had actually tried doing performance improvements for my game. And I had already tried all the methods you had suggested. Out of that, the third method really bombed badly ( although I thought that would be the best option). “setInterval()” brought the running framerate from 33 to 15 :-(

I agree that the game is quite heavy and was quite challenging to do performance improvement as there were quite a lot of moving objects in this game for a Flash game ( backgrounds, bees, hornets, spiders, webs etc ). But I had tuned it to work well at 35 fps. As i said above, the game seems to be working pretty well in the other websites. You can even see the game in Here is the link . The game is working fine.

So is there any specific problem or a fix that we can do for the kongregate version to improve its performance??

Flag Post

Thinking about it some more I can’t see any real advantage of (3) over (2). And given that you need extra interrupts &c, it must exert more of a performance penalty.

The key thing to realise is that you only get a maximum frame-rate of what you specify, and you may well get less. Just because flash has spent your last 2 frames dicking about, doesn’t mean that it tries to make them up later.

So you’re going to either need a frame-rate faster than what you want, or to perform game-cycles without displaying them.

I’ve just tried the following code, and it seems to work quite well in my game.

onEnterFrame = function() {
//outer frame rate limiter
var ttime:Number=getTimer();
if (ttime>oldtime+1000/FPS){//do the main loop (else do nothing)
oldtime+=1000/FPS; cycle goes here...

}//end of elapsed time testing
};//end of frame loop

I set the movie frame-rate to three or four times my game-cycle rate, and it runs well in the browser. If anything, its a bit faster than it was before in preview. Which suggests that even in preview you don’t get your full frame-rate.

Now this is quite naive code – if you have occasional massive processor burden then your game will run fast for a bit afterwards. So you’d have to account for that if necessary.

I think this essentially solves the problem for most lower-frame-rate games (20 fps and below). I don’t know how flash deals with enormous frame-rates, or what the overhead of frame entry is. In your case, TigerTail, perhaps you could test to see how far behind you are, and if it is too far, simply run through your game-loop twice.

Flag Post

Hey Lysis, I was just thinking of something which might be a crazy idea.

how about using a combination of both. Splitting the workload between a timer and the fps/onEnterFrame functions?

I think the one that would work best would be to use a FPS/OnEnterFrame call for movement of pixels and objects. As well likely Player actions (new commands)

While split off from that a second event say at 10 FPS to do Computer AI and other things which don’t need to be done as often. I am not sure if this extra workload will help the framerate, but it is a thought.

Flag Post

AAh, I remember writing a game in machine-code, and trying to get the game loop beyond reproach. Theres a lot of crap you need to do if you want things to work under most circumstances. It is probably a blessing in disguise that as flash developers we don’t have access to the internal gubbins of that. So we can only do the best we can.

Anyway, the documentation suggests that if you have an event called less often than the frame-rate, it gets called after a frame has been entered. So frankly that isn’t worth the bother. Reading player input under a fast interrupt might be, but that depends on what you’re doing.

Doing intensive processing over several frames may still be a good idea, if you have occasional spikes of work. But I think the two approaches I’ve outlined above (having a higher frame-rate and dropping events until you reach a suitable point, or having a moderate frame-rate and dropping display-frames) will probably suit almost all games more than adequately.

Flag Post

Kongregate’s Chat API causes some slowdown as it is taking up processing power. So add on the limitation of plugins in browsers, and you got a double whammy right there.