0
votes

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?

1

1 Answers

1
votes

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.