I have previously asked a question on AS3 and timing for games but got no answer so trying to make the question more precise.
I am making a game similar to Touhou in style to learn AS3, but this game is timed to music. Bullet patterns, enemy spawning and special graphics will all be timed to happen at specific times in the music. What I am wondering is:
What is the best way to accurately time many(!) events that are required to be very accurate and not slip even a tiny bit out of sync?
Example of what sort of timing I am looking:
s
Spawn 5 different types of enemy’s at 1:30 minutes, enemy 1 bullet pattern start at 1:31, bullet pattern will be timed to beat so repeat pattern every 2 seconds. This is a simple and short example of what I am trying to get at.
For object and animation timing, you should listen to
ENTER_FRAMEevent, then get the current time in miliseconds with:and check if any objects need to be moved, added, etc. based on that time.
As for sound timing, you will probably be fine by just normally playing sounds during the ENTER_FRAME event. But, flash is prone to adding latency to sounds, meaning that they will not always be played immediately after you call .play() on them (not too much, in order of milliseconds). If you need super precise timing, you might need to implement your own mixer, using the techniques described here and here.
Good luck!