Question

I am attempting to create a side scrolling shooter prototype in which the actions of the enemies and bullets are timed to a beat. The target bpm I am working towards is 120.

At the centre of this is obviously the timing of the sounds and I have begun by trying to create a metronome as a guide. I use the getTimer function to calculate the frame time and accumulate this value until it reaches the right time (500ms for 120bpm), then playing a sound.

As you can imagine, this doesn't give a constant result and suggests that's there is a better option. So my question is what is the most accurate method to time sounds for a game of this type? Is this a problem solely with the timing? I am using Haxe NME, could i be too far removed from the audio device to play sounds fast enough?

Was it helpful?

Solution

Playing a Sound will have different behavior on the different NME platforms, including different latencies. Even in plain old Flash, Sound.play and SoundChannel.position aren't very accurate!

For a rhythm game, you really do need low-level audio control, which NME doesn't currently have. If you are targeting Flash, you can use SampleDataEvent to dynamically mix the audio and get more accurate timing. There are plans to add cross-platform support for SampleDataEvent to NME in the future (source).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top