AS3 Timers vs. ENTER_FRAME performance

后端 未结 4 1920
有刺的猬
有刺的猬 2021-02-01 09:56

I\'m building a game that got some moving things all the time, so I\'m using a lot of Timer instances to control repetition and trigger motion.

Now the thing is that I

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-01 10:25

    The issue probably comes from the fact that timers aren't really reliable in that they aren't as fps independent as we think they are. When the framerate drops, for some reason the timers will get called less often as well. This is pretty different than the behavior in C, C++ or other OOP languages and thus many are falling for this trap.

    To avoid this, try to use the ENTER_FRAME event as a main game loop and inside that loop, evaluate the time to know if you need to do one or several updates to your game logic. That will make your code totally fps independent. You can use the flash.utils.getTimer call to get the time since launch.

    I wrote a post about this on my website: http://fabricebacquart.info/wordpress/?p=9

提交回复
热议问题