2013-07-17 63 views
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) 
+0

我不知道什麼樣的你正在使用的圖像,但物理對象的參考點始終是對象的中心。因此,如果您在沒有使用physics.setDrawMode(「調試」)屬性的情況下進行檢查,則可能會被誤導 –

回答

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 

保持編碼.......... :)