简体   繁体   中英

FLASH AS3 AIR 3.0 iOS: Timer optimization?

Right now in my code I have like 6-8 diffrent timers that have diffrent delays. Every Timer do spawn a diffrent thing to the stage. My question is just a simple one, would it be better if I could do ONE timer that could spawn everything? It that more optimized then? Would It make a different to the preformence of the game?

Simplefy: 8 different timers vs 1 huge timers containing every information that all the 8 timers hold together?

In general, game developers prefer to have a single timer run the entire thing. This is known as the main loop, the game loop, or the update loop.

That being said, many flash games have performance to spare, and the readability of using multiple timers may make it easier to get a finished game out there. Optimizing you code prematurely is as bad as not optimizing it at all.

If you game runs evenly on a variety of devices, without performance problems, then don't worry about refactoring the timers. Plus in a flash game, timers are unlikely to be the cause of performance issues. Rendering and creating new objects are. So be sure to profile your game if there are performance issues to discover what function calls are actually causing the problem before optimizing an area that may not be the culprit.

In short - there is not a one-way-to-code rule about using timers in games. But among the developers I know who make games, we use as few as possible as a matter of keeping the code simple, and being able to stop and start it with ease.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM