quick-cocos2dx 3.3 中如何侦听碰撞事件
来源:互联网 发布:提高记忆力的方法知乎 编辑:程序博客网 时间:2024/06/05 09:09
首先按照一般步骤创建物理世界,然后注册碰撞事件侦听器如下:
local contactListener = cc.EventListenerPhysicsContact:create() contactListener:registerScriptHandler(function(contact) print("contactBegin", "-----------", type(contact)) return true end, cc.Handler.EVENT_PHYSICS_CONTACT_BEGIN) contactListener:registerScriptHandler(function(contact, solve) print("contactPresolve", "-----------", type(contact), type(solve)) return true end, cc.Handler.EVENT_PHYSICS_CONTACT_PRESOLVE) contactListener:registerScriptHandler(function(contact, solve) print("contactPostsolve", "-----------", type(contact), type(solve)) end, cc.Handler.EVENT_PHYSICS_CONTACT_POSTSOLVE) contactListener:registerScriptHandler(function(contact) print("contactSeperate", "-----------", type(contact)) end, cc.Handler.EVENT_PHYSICS_CONTACT_SEPERATE) self:getEventDispatcher():addEventListenerWithFixedPriority(contactListener, 1)随后在设置想要侦听碰撞事件的刚体类型。
/** * A mask that defines which categories this physics body belongs to. * Every physics body in a scene can be assigned to up to 32 different categories, each corresponding to a bit in the bit mask. You define the mask values used in your game. In conjunction with the collisionBitMask and contactTestBitMask properties, you define which physics bodies interact with each other and when your game is notified of these interactions. * The default value is 0xFFFFFFFF (all bits set). */ void setCategoryBitmask(int bitmask); /** * A mask that defines which categories of bodies cause intersection notifications with this physics body. * When two bodies share the same space, each body’s category mask is tested against the other body’s contact mask by performing a logical AND operation. If either comparison results in a non-zero value, an PhysicsContact object is created and passed to the physics world’s delegate. For best performance, only set bits in the contacts mask for interactions you are interested in. * The default value is 0x00000000 (all bits cleared). */ void setContactTestBitmask(int bitmask); /** * A mask that defines which categories of physics bodies can collide with this physics body. * When two physics bodies contact each other, a collision may occur. This body’s collision mask is compared to the other body’s category mask by performing a logical AND operation. If the result is a non-zero value, then this body is affected by the collision. Each body independently chooses whether it wants to be affected by the other body. For example, you might use this to avoid collision calculations that would make negligible changes to a body’s velocity. * The default value is 0xFFFFFFFF (all bits set). */ void setCollisionBitmask(int bitmask);
CategoryBitmask与CollisionBitmask决定是否发生碰撞。
注意,默认是不发送碰撞事件,且均可发生碰撞的。
0 0
- quick-cocos2dx 3.3 中如何侦听碰撞事件
- cocos2dx 触摸侦听事件
- cocos2dx 事件侦听
- quick cocos2dx 鼠标事件
- 事件触摸-Quick-Cocos2dx
- c#如何绑定事件侦听
- quick-cocos2dx的addNodeEventListener事件
- quick cocos2dx 自定义事件管理器
- quick-cocos2dx中使用pomelo
- quick-cocos2dx中使用pomelo
- quick-coos2d-3.3中定时器/帧事件
- quick中自定义事件
- quick-cocos2dx 如何派生一个新类
- quick-cocos2dx 如何派生一个新类
- cocos2dx 3.0之 如何在Table中如何获取事件
- cocos2dx-碰撞
- cocos2dx 碰撞
- cocos2dx-碰撞
- android ProgressBar 自定义进度条颜色
- Windows Server 2003支持还有不到半年时间
- CSS的特殊性 (specificity)
- rich edit 改变某行或某个字符的颜色
- epoll学习过程心得
- quick-cocos2dx 3.3 中如何侦听碰撞事件
- 2014.12--不要因为一次挫折而放弃
- linux nohup
- Plus One
- java主函数的浅析
- 镀金的勇者
- 空压机供应,干燥机,过滤器,储气罐销售,贴心的四知堂服务
- android service组件总结
- JS闭包导致循环给按钮添加事件时总是执行最后一个