【发布时间】:2014-05-31 09:26:16
【问题描述】:
我是 Corona 开发的初学者,我必须确定 3 个对象之间的碰撞。事实上,这是我的代码:
The first object is my player :
player = display.newImageRect("ballon.png", 150,170 )
player.anchorX = 0.5
player.anchorY = 0.5
player.x = display.contentCenterX - 450
player.y = display.contentCenterY+250
physics.addBody(player, "static", {density=0.1, bounce=0.1, friction=0.1,})
player.myName="player"
screenGroup:insert(player)
第二个对象是在函数中创建的:
function addWindSlow(self,event)
height = math.random(display.contentCenterY - 200, display.contentCenterY + 200)
windslow = display.newImage( "wind-neg.png")
windslow.x = display.contentWidth
windslow.y = height
windslow.speed = 4
windslow.myName="windslow"
physics.addBody(windslow, "static", {density = 0.1, bounce = 0, isSensor = false})
elements:insert(windslow) end
function addWindFast(self,event)
height = math.random(display.contentCenterY - 200, display.contentCenterY + 200)
windfast = display.newImage( "wind-pos.png")
windfast.x = display.contentWidth
windfast.y = height
windfast.speed = 4
windfast.myName="windfast"
physics.addBody(windfast, "static", {density = 0.1, bounce = 0, isSensor = false})
elements:insert(windfast) end
最后,第三个对象是相同的,但称为“addWindFast() 与不同的图像”
所以我想知道,一旦我的玩家与 windslow 发生碰撞,我需要执行一个动作......如果它是对象 windfast,另一个动作。这是我的代码:
function onCollision( event )
if ( event.phase == "began" ) then
if event.other.windslow and event.other.isVisible==true then
print("windslow has been touch !")
end
end
结束
我发现了一些关于预碰撞的信息,我将在获得如何“识别”对象的信息后使用它...我需要防止碰撞并在玩家要触摸时避免它风速或风速。
感谢大家的付出!
【问题讨论】:
标签: lua collision-detection coronasdk