Using this code below, I have two sounds where a_sound uses Channel 1 and b_sound uses Channel 2.
When I touch the graphics I get the corresponding correct sounds. No problem.
BUT if I try and touch both graphics at the same time triggering both sounds simultaneously, I only hear one of the sounds. I thought if I put each sound on its own channel, I’d be able to hear the sounds together.
I should also mention I have a music track set up on Channel 21. I can play that music track and then tap the graphics above to the music track. So, it is possible to hear multiple sounds together but I can’t START two sounds together.
Is it because only one “began” of the event.phase is allowed at a time??
Here’s the test code I have:
local a_btn = display.newImage( “images/a_red_btn.png”, 105, 70 ) btnGroup:insert(a_btn)
local a_btnPush = display.newImage( “images/a_red_btnPush.png”, 105, 70 ); a_btnPush.alpha = 0, btnGroup:insert(a_btnPush)
local b_btn = display.newImage( “images/b_blue_btn.png”, 315, 70 ) btnGroup:insert(b_btn)
local b_btnPush = display.newImage( “images/b_blue_btnPush.png”, 315, 70 ); b_btnPush.alpha = 0, btnGroup:insert(b_btnPush)
a_sound = audio.loadSound( “sounds/a_sound.m4a” )
b_sound = audio.loadSound( “sounds/b_sound.m4a” )
local function showPush_a ( event )
if event.phase == “began” then
audio.play( a_sound, {channel=1} )
a_btn.alpha = 0
a_btnPush.alpha = 1
elseif event.phase == “ended” then
a_btn.alpha = 1
a_btnPush.alpha = 0
end
end
a_btn:addEventListener( “touch”, showPush_a )
a_btnPush:addEventListener( “touch”, showPush_a )
local function showPush_b ( event )
if event.phase == “began” then
b_btn.alpha = 0
b_btnPush.alpha = 1
audio.play( b_sound, {channel=2} )
elseif event.phase == “ended” then
b_btn.alpha = 1
b_btnPush.alpha = 0
end
end
b_btn:addEventListener( “touch”, showPush_b )
b_btnPush:addEventListener( “touch”, showPush_b )