Are you using a timer to make your player bounce and to play the rythm?
Also, do you know your track is at a constant BPM?
Because if you are, and the BPM is something that can be accurately divided into the correct time, your problem is likely with Corona’s timer system itself. A while ago, I created a library specifically to combat the timer inaccuracies, but it’s probably out of date now and it’s not hard to write one from scratch.
Basically, the way Corona’s timer works is like so:
[lua]
each frame:
if timerStartTime + timerDelayTime >= frameTime then
doTimerListener()
timerStartTime = frameTime
done
done
[/lua]
The problem is in that check. if timerStartTime + timerDelayTime checks for if the time has passed, but, since the FPS is never perfect and is gauged in increments of 16 or 33 ms, and the timer sets the start time to the frame time, each iteration you lose a few milliseconds. That’s fine if all you’re doing is a particle effect, but for more accuracy, it’s unnacceptable. If you have a timer running every 100 ms that starts at time 5 ms, it actually ends up like this (real timer values printed from the simulator):
2015-01-21 07:01:23.076 Corona Simulator[576:10375] 338.858
2015-01-21 07:01:23.197 Corona Simulator[576:10375] 459.242
2015-01-21 07:01:23.329 Corona Simulator[576:10375] 590.924
2015-01-21 07:01:23.461 Corona Simulator[576:10375] 723.044
2015-01-21 07:01:23.592 Corona Simulator[576:10375] 854.252
2015-01-21 07:01:23.725 Corona Simulator[576:10375] 987.251
2015-01-21 07:01:23.862 Corona Simulator[576:10375] 1124.685
2015-01-21 07:01:23.989 Corona Simulator[576:10375] 1251.183
2015-01-21 07:01:24.121 Corona Simulator[576:10375] 1383.132
2015-01-21 07:01:24.252 Corona Simulator[576:10375] 1514.608
2015-01-21 07:01:24.385 Corona Simulator[576:10375] 1647.011
2015-01-21 07:01:24.516 Corona Simulator[576:10375] 1778.199
See the horrific inaccuracies? The first time we ran at 338, the second time should be 438, right? Wrong! It’s 459! We just lost 21 ms in one iteration!
The way you can handle timers so that they’re accurate is by keeping a counter of iterations and checking for startTime + iterations * delay instead.
Here’s a full program with an accurate timer vs the built-in timer, both set to 100 ms delay, and a status check for how many times each one’s run:
local accurateTimer = { delay = 100, startTime = 0, nextTime = 0, iterations = 0, onTimer = function(time) print(time) end } -------------------------------------------------------------------------------- -- Update Timer -------------------------------------------------------------------------------- accurateTimer.update = function(event) if event.time \>= accurateTimer.nextTime then accurateTimer.onTimer(event.time) accurateTimer.iterations = accurateTimer.iterations + 1 accurateTimer.nextTime = accurateTimer.startTime + accurateTimer.iterations \* accurateTimer.delay end end accurateTimer.start = function(delay) accurateTimer.delay = delay accurateTimer.startTime = system.getTimer() accurateTimer.nextTime = accurateTimer.startTime + accurateTimer.delay end local badTimerIterations = 0 local badTimer = timer.performWithDelay(100, function() badTimerIterations = badTimerIterations + 1 end, 0) accurateTimer.start(100) Runtime:addEventListener("enterFrame", accurateTimer.update) timer.performWithDelay(5000, function() print("TIME: " .. (system.getTimer() - accurateTimer.startTime) .. "; ACC: " .. accurateTimer.iterations - 1 .. "; BAD: " .. badTimerIterations) end, 0)
By the way, in the above example, I used a timer.performWithDelay to do the status check, but that’s fine because I also print out the true time.