即使我设置了groupIndex - / +,对象仍然会发生碰撞

时间:2015-09-21 09:26:23

标签: lua corona collision

我有4个相同类型的物体,地雷和另一个我不想与任何其他物体碰撞的物体。我将4个对象的groupIndex设置为正,而将另一个对象设置为负。对于其中的两个地雷它可以工作,但是另外两个它会发生碰撞。

以下是对象:

mine=display.newImage("mine.png")
mine:setReferencePoint(display.BottomLeftReferencePoint)
mine.y=-200
mine.x=math.random(0,280)
physics.addBody(mine, "static", {density=0, bounce=0, friction=0, radius=12})
mine.isVisible=true
local mineCollisionFilter = { groupIndex = 2 }

mine2=display.newImage("mine.png")
mine2:setReferencePoint(display.BottomLeftReferencePoint)
mine2.y=-400
mine2.x=math.random(0,280)
physics.addBody(mine2, "static", {density=0, bounce=0, friction=0, radius=12})
mine2.isVisible=true
local mine2CollisionFilter = { groupIndex = 3 }

mine3=display.newImage("mine.png")
mine3:setReferencePoint(display.BottomLeftReferencePoint)
mine3.y=-50
mine3.x=math.random(0,280)
physics.addBody(mine3, "static", {density=0, bounce=0, friction=0,     radius=12})
mine3.isVisible=true
local mine3CollisionFilter = { groupIndex = 4 }

mine4=display.newImage("mine.png")
mine4:setReferencePoint(display.BottomLeftReferencePoint)
mine4.y=-400
mine4.x=math.random(0,280)
physics.addBody(mine4, "static", {density=0, bounce=0, friction=0,r adius=12})
mine4.isVisible=true
local mine4CollisionFilter = { groupIndex = 5 }

function  salvareF(event)
salvare=display.newImage("RedButton.png")
salvare.x=math.random(0,300)
salvare.y=0
salvare.height=30
salvare.width=30
physics.addBody( salvare, "dynamic", {density=0, bounce=0, friction=0, radius=12} )
salvare.gravityScale=0
salvare:setLinearVelocity( 0,350 )
salvare.isVisible=true
salvare.collision=evCollision
local salvareCollisionFilter = { groupIndex=-6 }
salvare:addEventListener("collision", salvare)

end

0 个答案:

没有答案