Hi all! I’m having problems with sounds in collisions, not basic sounds, but sounds that come out in a specific time. My game is similar to a pinball game and the problem I have is that I want to disappear an object in a certain time and play a sound when it disappears, not when the collision occurs.
This is the code that is inside the collision listener
--initially the boolean playSound is false. local function onLocalCollision( self, event ) if (self.id == "ball" and event.other.id == "obt\_1") or (self.id == "ball" and event.other.id == "obt\_2") or (self.id == "ball" and event.other.id == "obt\_3") or (self.id == "ball" and event.other.id == "obt\_4") or (self.id == "ball" and event.other.id == "obt\_5") then print("ball and obt collision") audio.play( pin ) --official audio of the collision playSound = true remove = timer.performWithDelay(1000, function() if playSound == true then audio.play( clear ) playSound = false print( "audio payed" ) end display.remove( event.other ) print( event.other.id ) print( "obt removed" ) end ) end end
Each time the ball collides with the other object playSound is true and the timer is supposed to run.
The problem is when the ball collides in less than 1 second with another object with a similar characteristic, the object disappears but no sound is heard.
Thanks in advance
DoDI