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!