标签:dev pos cti event and creat create script end
我搜到的网上的碰撞检测都是规则几何碰撞,例如矩形、立方体,三角形,这些都是小学的几何知识。
关键是不规则几何的碰撞,但是没有搜到好的文章的。
https://blog.csdn.net/A632189007/article/details/78126588
这里记录一下cocos2dx中的相关api
1 2d碰撞检测
local conListener = cc.EventListenerPhysicsContact:create() conListener:registerScriptHandler(function (contact) -- body local node1 = contact:getShapeA():getBody():getNode() local node2 = contact:getShapeB():getBody():getNode() print("node contacted name EVENT_PHYSICS_CONTACT_BEGIN") print(node1:getName()) print(node2:getName()) return true end, cc.Handler.EVENT_PHYSICS_CONTACT_BEGIN ) conListener:registerScriptHandler(function (contact) -- body local node1 = contact:getShapeA():getBody():getNode() local node2 = contact:getShapeB():getBody():getNode() print("node contacted name EVENT_PHYSICS_CONTACT_PRESOLVE") print(node1:getName()) print(node2:getName()) end, cc.Handler.EVENT_PHYSICS_CONTACT_PRESOLVE ) conListener:registerScriptHandler(function (contact) -- body local node1 = contact:getShapeA():getBody():getNode() local node2 = contact:getShapeB():getBody():getNode() print("node contacted name EVENT_PHYSICS_CONTACT_POSTSOLVE") print(node1:getName()) print(node2:getName()) end, cc.Handler.EVENT_PHYSICS_CONTACT_POSTSOLVE ) conListener:registerScriptHandler(function (contact) -- body local node1 = contact:getShapeA():getBody():getNode() local node2 = contact:getShapeB():getBody():getNode() print("node contacted name EVENT_PHYSICS_CONTACT_SEPARATE") print(node1:getName()) print(node2:getName()) return true end, cc.Handler.EVENT_PHYSICS_CONTACT_SEPARATE ) cc.Director:getInstance():getEventDispatcher():addEventListenerWithSceneGraphPriority(conListener, scene)
标签:dev pos cti event and creat create script end
原文地址:https://www.cnblogs.com/afraidToForget/p/8782514.html