chipchunp 碰撞点坐标
local function onContactBegin(contact)--产生了碰撞
local a = contact:getShapeA():getBody():getNode()
local b = contact:getShapeB():getBody():getNode()
dump(contact:getContactData().points)
--碰撞点
local points = contact:getContactData().points
if a:getName() == "player" then
if b.collide then
b:collide(a,points)
end
else
print("物体碰撞到人")
--物体碰撞到人
a:collide(b,points)
end
return true
end
local function onContactSeperate(contact)--接触分离
if self.player.blood <= 0 then
self.backgroundLayer:unscheduleUpdate()
self.player:die()
local over = display.newSprite("image/over.png")
:pos(display.cx, display.cy)
:addTo(self)
cc.Director:getInstance():getEventDispatcher():removeAllEventListeners()
end
end
local contactListener = cc.EventListenerPhysicsContact:create()
contactListener:registerScriptHandler(onContactBegin, cc.Handler.EVENT_PHYSICS_CONTACT_BEGIN)
contactListener:registerScriptHandler(onContactSeperate, cc.Handler.EVENT_PHYSICS_CONTACT_SEPERATE)
local eventDispatcher = cc.Director:getInstance():getEventDispatcher()
eventDispatcher:addEventListenerWithFixedPriority(contactListener, 1)