AS3: How accurate are the getTimer() method and the Timer class?

前端 未结 5 2045
走了就别回头了
走了就别回头了 2020-12-21 08:48

I\'m in the process of making a game (a shmup) and I\'ve started to question the accuracy of the timers in ActionScript. Sure, they\'re accurate enough when you want to tim

5条回答
  •  渐次进展
    2020-12-21 09:26

    Intead of using the timer class at all, I would put my update code in and enterframe eventlistener.

    Then use getTimer(), to find out how much time has passed since last update, and then a bit of bit of math to calculate movement, laser "spawning" etc. This way the game should perform the same no matter if you getting 60FPS or 10FPS.

    This also prevents weird game behavior if the the FPS drop temporary, or if the game is running on a slow machine.

    For the most part the math is pretty simple, and when it is not, you can usually "cut corners" and still get a result good enough for a game. For simple movement you can simply multiply movement offset with time since last update. For acceleration, you need a second degree equation, but could simplify be multiplying again.

    In response to jorelli comment below:

    The collision detection problem can be solved by better code, that does not just check the current state, but also what happened between the previous state and the current. I've never had problems with the keyboard. Maybe you should try this nifty little class: http://www.bigroom.co.uk/blog/polling-the-keyboard-in-actionscript-3

提交回复
热议问题