Grpahics mixed with tempo delay

Hello, 

I have been working in a game that involves graphics with tempos. Here’s a video (https://youtu.be/9DAdsRXbvBw) that demostrates a bar that should be filled according the tempo the sound is giving me. 

Video of example: https://youtu.be/9DAdsRXbvBw

The problem is that it start on time and it follows the first couple of cycles. But as time pass the indicator starts to get behind. I don’t know if any of you here have worked in something similar mixing graphics with tempos. If you could give me a hint on how to approach it. 

Here is the code I’m using:

function scene:create( event ) local sceneGroup = self.view audio.play( sound\_bit ) local background = display.newImageRect( "Images/Fire/background.png", display.contentWidth, display.contentHeight ) background.anchorX, background.anchorY, background.x, background.y = 0, 0, 0, 0 sceneGroup:insert( background ) local barraBackground = display.newRect( 0, 0, 170, 30 ) barraBackground:setFillColor( 0.858, 0.858, 0.858) barraBackground.x, barraBackground.y = w \* 0.5, h \* 0.2 sceneGroup:insert( barraBackground ) local barra = display.newImageRect( "Images/Fire/barra2.png", 170, 30 ) barra.x, barra.y = display.contentWidth \* 0.5, display.contentHeight \* 0.2 sceneGroup:insert( barra ) local barraMask = graphics.newMask( "Images/Fire/mascara-barra.png" ) barra:setMask( barraMask ) barra.maskX = mascara local function moveMask( ) if touch then if(barra.maskX \< 84) then barra.maskX = barra.maskX + 7.9 print(barra.maskX) --Runtime:removeEventListener( "enterFrame", moveMask ) --touch = false else touch = false barra.maskX = mascara Runtime:removeEventListener( "enterFrame", moveMask ) print("termina2") end end end local function fillMask() barra.maskX = mascara if barra.maskX \< 84 and not touch then touch = true barra.maskX = barra.maskX + 7 print(barra.maskX) Runtime:addEventListener( "enterFrame", moveMask ) end end timer.performWithDelay( 833, fillMask, 0 ) end

Thank you!

Many people will try to tell you that you can’t do accurate timing with Corona, but this is simply not true. All you need is a more accurate timer. And “accurate” here doesn’t mean accurate in the sense of “close” response (the most you’ll get is 16 ms), it just means the accuracy of each following tick. I’m thinking of posting something about this on my website, but in the meantime, here’s a forum topic about it:

https://forums.coronalabs.com/topic/54004-rhythm-based-game-how-to-stay-in-sync/

  • Caleb

Thank you, it really worked for me. I would just like to know if there is a way to stop the timer. 

The code I gave as an example is just a super-basic proof-of-concept. It just demonstrates the idea and that the idea works. For anything “real”, you’d need to expand it while using the same basic concept. All the concept is that, instead of adding time to previous call to find the next call, multiply time by number of iterations to find the next call.

  • Caleb

Many people will try to tell you that you can’t do accurate timing with Corona, but this is simply not true. All you need is a more accurate timer. And “accurate” here doesn’t mean accurate in the sense of “close” response (the most you’ll get is 16 ms), it just means the accuracy of each following tick. I’m thinking of posting something about this on my website, but in the meantime, here’s a forum topic about it:

https://forums.coronalabs.com/topic/54004-rhythm-based-game-how-to-stay-in-sync/

  • Caleb

Thank you, it really worked for me. I would just like to know if there is a way to stop the timer. 

The code I gave as an example is just a super-basic proof-of-concept. It just demonstrates the idea and that the idea works. For anything “real”, you’d need to expand it while using the same basic concept. All the concept is that, instead of adding time to previous call to find the next call, multiply time by number of iterations to find the next call.

  • Caleb