views:

53

answers:

2

My Flash game targets 24 fps, but slows to 10 on slower machines. This is fine, except Flash decides to throttle the queue of incoming MouseEvent and KeyboardEvents, and they stack up and the Events fall behind. Way behind. It's so bad that, at 10 fps, if I spam the Mouse and Keyboard for a few seconds not much happens, then, after I stop, the game seems to play itself for the next 5 seconds as the Events trickle in. Spooky, I know.

Does anyone know a way around this? I basically need to say to Flash, "I know you think we're falling behind, but throttling the input events won't help. Give them to me as soon as you get them, please."

+2  A: 

You'll probably have better luck working to increase your framerate instead of trying to work around a side-effect of the low framerate problem. Have you used a profiler to identify why the framerate is so slow? Can you utilize invalidation to improve it? Are there bottlenecks that can be optimized?

Sam
Thanks for the reply. It's a massively multiplayer game, so gracefully handling moderate framerate dips gives us important flexibility. Without this strange input behavior, the game stays playable even when a slow machine + a complicated scene pushes us down to 12-15 fps for a few seconds. Since the game runs well on most machines most of the time; further optimizations could then be 'spent' on allowing more players and opponents on screen.
Matt W
A: 

I don't think flash is throttling the input events. I think it's more likely that your application truly cannot process them quickly enough. I think the only way to stop them from 'stacking up' in this way, would be to completely discard events. So you'd need something in your code like:

function onKeyPress() {
  if(inputIsTooFarBehind()) 
    return; // skip this keypress

  // process keypress as normal
}

But there's a drawback...users will now have some of their commands discarded, and will simply click more and more to try and get their commands to work.

Perhaps you should work on designing the game in such a way that doesn't need such excessive key/mouse presses? Or go with Sam's suggestion to optimize the game itself to prevent it slowing down in the first place.

davr