Is there a way to skip drawing frames?
setInterval
and sometimes does heavy calculations. The problem is that on slower machines these calculations can't kee开发者_运维问答p up with the framerate and the movie slows down BUT the timers are unaffected what makes them asynchronous to the movie. Looking back, it was a bad idea to use timers but I can't change it back now. So...
is there a way to skip drawing frames? It would be OK if the game has a slower framerate on some areas but keeps up with the timers. Or do you have any other ideas how to solve my problem? I'm using AS2 btw.The solution is to either use time-based measures, or frame-based measures, not mix-and-match the two.
The preferred solution would be to use getTime()
in all your frame events to determine how much time has elapsed since the previous frame, and hence how much you need to do in that event.
How about splitting your updates into two areas: update() where you would only update values you will use later for rendering and draw()/render() where you would have all your graphics related code ?
You have a frame skip variable you would use in an onEnterFrame to render when you need to.
e.g.
onEnterFrame = function(){
update();
if(_currentframe % frameSkip == 0) draw();
}
HTH
精彩评论