Hello!
2 Questions!
#1: When I trigger a media.newEventSound, sometimes it plays twice? Does anyone know why?
local scoreSound = media.newEventSound("scoresound.wav")
media.playEventSound(scoreSound)
#2: I have a game with balls that bounce and everytime they bounce and depending on what they hit I fire a sound like so:
local bounces = {
[1] = media.newEventSound("duns1.wav"),
[2] = media.newEventSound("duns2.wav"),
[3] = media.newEventSound("duns3.wav"),
[4] = media.newEventSound("duns4.wav"),
[5] = media.newEventSound("duns5.wav"),
[6] = media.newEventSound("duns6.wav"),
[7] = media.newEventSound("bollduns1.wav"),
[8] = media.newEventSound("bollduns2.wav"),
[9] = media.newEventSound("bollduns3.wav"),
[10] = media.newEventSound("bollduns4.wav"),
[11] = media.newEventSound("bollduns5.wav"),
[12] = media.newEventSound("bollduns6.wav")
}
local function randomSound1 ()
local choice = math.random( 1, 6 )
media.playEventSound( bounces[choice] )
end
local function randomSound2()
local choice2 = math.random( 7, 12 )
media.playEventSound( bounces[choice2] )
end
--sound effects on bounce
local function onCollision( event )
if ( event.phase == "began" ) then
if(event.object1.name == nil) then -- if ball hits a wall.
randomSound2()
elseif (event.object1.Group == "Ball") then
randomSound1()
end
end
I am using director class for screen transitioning and if I replay the level a couple of times the sounds fire multiple times.
I have made a cleaning function to remove the eventlistener before replay but maybe its not working?
How come the sounds go off multiple times?
Hope to hear from you guys! Bye! [import]uid: 199163 topic_id: 33673 reply_id: 333673[/import]
