碰撞不在天花板上工作

时间:2013-07-17 21:29:15

标签: lua corona

所有碰撞都在起作用,除了“天花板”我在这里错过了什么?

local screenGroup = self.view

jetSpriteSheet = sprite.newSpriteSheet("helicopters.png", 97, 55) 
jetSprites = sprite.newSpriteSet(jetSpriteSheet, 1, 4)
sprite.add(jetSprites, "jets", 1, 8, 600, 0)
jet = sprite.newSprite(jetSprites)
jet.x = -80
jet.y = 350
jet:prepare("jets")
jet:play()
jet.collided = false
jet.name = "jetplayer"

physics.addBody(jet, "dynamic", {density=.1, bounce=0.1, friction=.2, radius=10, filter=playerCollisionFilter } )   
jet.gravityScale = 0

jetIntro = transition.to(jet,{time=2000, x=150, onComplete=jetReady})
screenGroup:insert(jet)

ceiling = display.newImage("invisibleTile.png")
ceiling.name = "ceiling"
ceiling:setReferencePoint(display.BottomLeftReferencePoint)
ceiling.x = 0
ceiling.y = 0

physics.addBody(ceiling, "static", {density=.1, bounce=0.1, friction=.2,} )  
screenGroup:insert(ceiling)

local function onCollision(event)
    if event.phase == "began" and gameIsActive == true then
    local obj1 = event.object1; 
    local obj2 = event.object2; 
        if obj1.name == "jetplayer" then
            if     obj2.name == "BCloud1" then MinLife()
            elseif obj2.name == "BCloud2" then pontsMin10()
            elseif obj2.name == "BCloud3" then pontsMin20()
            elseif obj2.name == "GCloud1" then pontsplus50()
            elseif obj2.name == "ceiling" then explode()
            elseif obj2.name == "theFloor" then explode()
            end
        end
    end
end
Runtime:addEventListener( "collision", onCollision )

1 个答案:

答案 0 :(得分:1)

只需替换以下行:

physics.addBody(app, "dynamic", {density=.1, bounce=0.1, friction=.2, radius=10, filter=playerCollisionFilter } )

如下,再次检查:

physics.addBody(app, "dynamic", {density=.1, bounce=0.1, friction=.2,filter=playerCollisionFilter } )

我并不完全了解日冕的这种行为。这里,半径为jetplayer的对象被选为obj2。因此,如果不需要,您可以删除半径,或将函数更改为:

if(obj1.name == "jetplayer" or obj2.name == "jetplayer")then
    if(obj1.name == "ceiling" or obj2.name == "ceiling")then
        explode()
    end
end

保持编码..........:)