I’m writing a game where I move an object by a swiping motion. Along with the motion a “whoosh” sound is to be played.
In the emulator all is well, but on the device (Samsung Galaxy S5) the audio is clearly delayed and the effect is awful. I have made a minimal example showing this below. The screen changes color when a (horizontal) swipe is detected and then the sound is played a bit delayed:
local MIN\_SWIPE\_LEN = 30 local bg = display.newRect(display.contentWidth/2, display.contentHeight/2, display.contentWidth, display.contentHeight); local whoshSound = audio.loadSound("audio/whosh.wav") -- Channel 1 local inSwipe = false local touchHandler = function(e) local dx = e.x - e.xStart local dy = e.y - e.yStart if (e.phase == "began") then end if (e.phase == "moved") then if (math.abs(dx) \> MIN\_SWIPE\_LEN and inSwipe == false) then bg:setFillColor(math.random(50,100)/100, math.random(50,100)/100, math.random(50,100)/100) audio.stop(1) audio.play(whoshSound, {channel=1,loops=0}) inSwipe = true end end if (e.phase == "ended") then inSwipe = false end return true end Runtime:addEventListener( "touch", touchHandler )
Am I doing anything wrong?
I’m using Corona SDK Public 2014.2393