2015-05-26 50 views
0

我就喜歡玩這個聲音科羅娜SDK:播放聲音時,對象是在指定區域

audio.play(colsound) 
時,我的球穿過障礙物

(有obst1之間的自由空間和obst2)

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或設置physics.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

我已經這樣做了,但是當對象與另一個對象碰撞時,它會阻止它通過,我添加了一些透明的光禿禿的,但一方面防止它穿過(隧道),另一方面手它改變我的球(主要對象)x和y和對象開始飛行.... –