Corona sdk:当对象在指定区域时播放声音

时间:2015-05-26 14:09:32

标签: audio corona

我想播放这个声音

audio.play(colsound) 

当我的球穿过障碍物时(在障碍物和障碍物2之间有一个自由空间)

ball = display.newImage("ball.png")
    ball.x = 100; ball.y = 100
    physics.addBody(ball, "dynamic", {density=.05, bounce=0.1, friction=.2, radius=12})
    screenGroup:insert(ball)
    ball.myName = "ball"

    ----
    obst1 = display.newImage("obst1.png")
    obst1.x = 640; obst1.y = -500
    obst1.speed = 3
    physics.addBody(obst1, "static", {friction=0.5, bounce=0.3, density=.1 })
    screenGroup:insert(obst1)
    obst1.myName = "obst1"


    obst2 = display.newImage("obst2.png")
    obst2.x = 640; obst2.y = 500
    obst2.speed = 3
    physics.addBody(obst2, "static", {friction=0.5, bounce=0.3, density=.1 })
    screenGroup:insert(obst2)
    obst2.myName = "obst2"

(当鸟儿穿过管子时,就像飞鸟一样,声音弹出......)。

这是我用来检测碰撞和播放声音的代码,我在Obst1和Obst2之间放置的物体阻止球通过(我应该将速度设置为0还是设置物理.setContinuous(false))

function onCollision (event)

    if (event.object1.myName == "obst1") or (event.object1.myName == "obst2") then 
    storyboard.gotoScene("restart", "fade", 400)
    audio.stop()

    end

    if (event.object1.myName == "obst3") then 
    audio.play(colsound)  

    end
    if (event.object1.myName == "t") then  --the transparent object
    audio.play(colsound, 1) 
    end
end

1 个答案:

答案 0 :(得分:1)

将一个物理对象放在两个障碍物的中间,找到碰撞来播放音频。