2013-02-27 20 views
0

在下面的代碼行6我已經添加了一個Runtime:addEventListener("collision", onCollision),但它與一切與身體交互,如何排除碰撞監聽器在這種情況下,在這種情況下'BCloud1.png'排除碰撞偵聽器的一個對象

function getRandomStar() 
    local temp = starTable[math.random(1, #starTable)] -- Get a random star from starTable 
    local randomStar = display.newImage(temp.imgpath) -- Set image path for object 

    if (temp.imgpath == "BCloud1.png") then 
    physics.addBody(randomStar, "static", { density=.1, bounce=.1, friction=.2, radius=45 }) 
    Runtime:addEventListener("collision", onCollision) 
    temp.imgpath = "BCloud"..tostring(math.random(1, 3))..".png"; 
    end 

    if (temp.imgpath == "BCloud2.png") then 
    temp.imgpath = "BCloud"..tostring(math.random(1, 3))..".png"; 
    physics.addBody(randomStar, "static", { density=.1, bounce=.1, friction=.2, radius=45 }) 
    end 

    if (temp.imgpath == "BCloud3.png") then 
    temp.imgpath = "BCloud"..tostring(math.random(1, 3))..".png"; 
    physics.addBody(randomStar, "static", { density=.1, bounce=.1, friction=.2, radius=45 }) 
    end 

    randomStar.myName = "star" -- Set the name of the object to star 
    randomStar.movementSpeed = temp.movementSpeed; -- Set how fast the object will move 
    randomStar.x = math.random(-30, _W);  
    randomStar.y = -35; 
    randomStar.rotation = math.random(0,20) -- Rotate the object 

    starMove = transition.to(randomStar, { 
     time=randomStar.movementSpeed, 
     y=500, 
     onComplete = function(self) self.parent:remove(self); self = nil; 
     end 
     }) -- Move the star 
end--END getRandomStar() 

回答

1

如果你想使用

Runtime:addEventListener("collision", onCollision) 

和控制與什麼什麼碰撞,然後用碰撞過濾器。他們看起來容易得多。

這是我在學習關於它們時使用的教程。

Collision Filters