0
所有的碰撞正在工作,除了「天花板」我在這裏錯過了什麼?碰撞不在天花板上
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)
我不知道什麼樣的你正在使用的圖像,但物理對象的參考點始終是對象的中心。因此,如果您在沒有使用physics.setDrawMode(「調試」)屬性的情況下進行檢查,則可能會被誤導 –