gpt4 book ai didi

audio - 电晕sdk:当对象在指定区域中时播放声音

转载 作者:行者123 更新时间:2023-12-03 00:43:23 25 4
gpt4 key购买 nike

我想播放这种声音

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(假))
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

最佳答案

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

关于audio - 电晕sdk:当对象在指定区域中时播放声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30460998/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com