cocos2d 物理引擎cbbe body physicssbody怎么设置碰撞条件

实例介绍Cocos2d-x中Box2D物理引擎:碰撞检测
在Box2D中碰撞事件通过实现b2ContactListener类函数实现,b2ContactListener是Box2D提供的抽象类,它的抽象函数:
virtual void BeginContact(b2Contact* contact)。两个物体开始接触时会响应,但只调用一次。
virtual void EndContact(b2Contact* contact)。分离时响应。但只调用一次。
virtual void PreSolve(b2Contact* contact, const b2Manifold* oldManifold)。持续接触时响应,它会被多次调用。
virtual void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse)。持续接触时响应,调用完preSolve后调用。
下面通过将12.2.3一节的实例采用Box2D技术重构,了解一下Box2d物理引擎中如何检测碰撞。
首先我们需要在工程中添加一个新类。使用Visual Studio 2012中添加一个新类,需要分别添加C++源文件和头文件。具体操作,如图所示,右键点击工程HelloBox2D下的Classes文件夹,在右键菜单中选择,&添加&& &新项目&。弹出如后面的图所示添加新项对话框,我们在对话框中选择文件的种类,在&名称&中输入文件名ContactListener,然后点击&添加&按钮添加文件。
Visual Studio 2012中添加新类
添加新项对话框添加完成新类ContactListener,我们还需要修改它的代码,ContactListener.h文件代码如下:
#include cocos2d.h
#include Box2D/Box2D.h
USING_NS_CC;
class ContactListener : public b2ContactListener
//两个物体开始接触时会响应
virtual void BeginContact(b2Contact* contact);
//持续接触时响应
virtual void PreSolve(b2Contact* contact, const b2Manifold* oldManifold);
//持续接触时响应,调用完preSolve后调用
virtual void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse);
//分离时响应
virtual void EndContact(b2Contact* contact);
在头文件中需要引入cocos2d.h和Box2D/Box2D.h头文件,否则会有编译错误。ContactListener采用共有继承b2ContactListener。
ContactListener.cpp文件代码如下:
#include ContactListener.h
void ContactListener::BeginContact(b2Contact* contact)
log(BeginContact);
b2Body* bodyA = contact-&GetFixtureA()-&GetBody();
b2Body* bodyB = contact-&GetFixtureB()-&GetBody();
auto spriteA = (Sprite*)bodyA-&GetUserData();
auto spriteB = (Sprite*)bodyB-&GetUserData();
if (spriteA != nullptr && spriteB != nullptr)
spriteA-&setColor(Color3B::YELLOW);
spriteB-&setColor(Color3B::YELLOW);
void ContactListener::EndContact(b2Contact* contact)
log(EndContact);
b2Body* bodyA = contact-&GetFixtureA()-&GetBody();
b2Body* bodyB = contact-&GetFixtureB()-&GetBody();
auto spriteA = (Sprite*)bodyA-&GetUserData();
auto spriteB = (Sprite*)bodyB-&GetUserData();
if (spriteA != nullptr && spriteB != nullptr)
spriteA-&setColor(Color3B::WHITE);
spriteB-&setColor(Color3B::WHITE);
void ContactListener::PreSolve(b2Contact* contact, const b2Manifold* oldManifold)
log(PreSolve);
void ContactListener::PostSolve(b2Contact* contact, const b2ContactImpulse* impulse)
log(PostSolve);
上述代码第①行是实现碰撞事件BeginContact函数,第②代码和第③行代码是获得接触双方物体对象。第④代码和第⑤行代码是从物体对象的UserData属性中确定精灵对象,UserData属性可以放置任何对象,这里我们能够通过bodyA-&GetUserData()语句取得精灵,那是因为在定义物体的时候通过body-&SetUserData(sprite)语句,将精灵放入到物体的UserData属性。第⑥行代码是判断两个精灵是否存在。
代码第⑦行是实现碰撞事件EndContact函数,函数的实现与BeginContact函数类似。第⑧和第⑨行代码是实现碰撞事件PreSolve和PostSolve函数,这两个函数通常用的不多。
我们还需要在要监听事件的层中,添加相关碰撞检测代码。在HelloWorld.h的代码如下:
#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__
#include cocos2d.h
#include Box2D/Box2D.h
#include ContactListener.h
#define PTM_RATIO 32
class HelloWorld : public cocos2d::Layer
ContactListener* contactL
~HelloWorld();
static cocos2d::Scene* createScene();
virtual bool init();
virtual void update(float dt);
virtual bool onTouchBegan(cocos2d::Touch* touch, cocos2d::Event* event);
CREATE_FUNC(HelloWorld);
void initPhysics();
void addNewSpriteAtPosition(cocos2d::Vec2 p);
#endif // __HELLOWORLD_SCENE_H__
上述代码第①行是引入头文件ContactListener.h。第②行代码是声明ContactListener类型的成员变量contactListener。
我们还需要修改HelloWorld.cpp中的HelloWorld::initPhysics()代码如下:
void HelloWorld::initPhysics()
contactListener = new ContactListener();
world-&SetContactListener(contactListener);
函数中的contactListener = new ContactListener()语句是创建ContactListener对象,采用了new关键字分配内存,创建成员变量contactListener,需要自己释放contactListener对象。这些释放过程是在析构函数中进行,它的析构函数代码如下:
HelloWorld::~HelloWorld()
CC_SAFE_DELETE(world);
CC_SAFE_DELETE(contactListener);
使用CC_SAFE_DELETE(contactListener)安全释放contactListener成员变量的内存。
(window.slotbydup=window.slotbydup || []).push({
id: '2467140',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467141',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467143',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467148',
container: s,
size: '1000,90',
display: 'inlay-fix'mass:质量
moment:力矩,当他碰到另一个刚体时候 ,会产生一股扭转力,做旋转运动
body:刚体,表示物理世界中的抽象实体,附带有物理属性
shape:刚体的形状,同一个body可以附加多个shape 该shape们不会发生碰撞
joint:关节,可以连接&=2个刚体
&/** 创建一个body &mass和moment为默认值 &*/
& static PhysicsBody* create();
& /** 创建一个质量为mass的body moment为默认值. */
& static PhysicsBody* create(float mass);
& /** 创建一个body 并为mass 和moment赋值 */
& static PhysicsBody* create(float mass, float moment);
& /**创建一个shape为圆形的body */
& static PhysicsBody* createCircle(float radius, const PhysicsMaterial& material = PHYSICSBODY_MATERIAL_DEFAULT, const Point& offset = Point::ZERO);
& /** 创建一个shape为四边形的body. */
& static PhysicsBody* createBox(const Size& size, const PhysicsMaterial& material = PHYSICSBODY_MATERIAL_DEFAULT, const Point& offset = Point::ZERO);
& /**创建一个动态多边形刚体,多边形的顶点存放在Point array[ ]中 &示例:Point array[ ]={ point(1,1),point(2,2)} &注意:顶点必须按顺时针存放,并且图形为凸状,不能是凹的*/
& static PhysicsBody* createPolygon(const Point* points, int count, const PhysicsMaterial& material = PHYSICSBODY_MATERIAL_DEFAULT, const Point& offset = Point::ZERO);
& /** 创建一个静态的线状刚体. */
& static PhysicsBody* createEdgeSegment(const Point& a, const Point& b, const PhysicsMaterial& material = PHYSICSBODY_MATERIAL_DEFAULT, float border = 1);
& /** 创建一个静态四边形刚体. */
& static PhysicsBody* createEdgeBox(const Size& size, const PhysicsMaterial& material = PHYSICSBODY_MATERIAL_DEFAULT, float border = 1, const Point& offset = Point::ZERO);
& /** 创建一个静态多边形刚体. */
& static PhysicsBody* createEdgePolygon(const Point* points, int count, const PhysicsMaterial& material = PHYSICSBODY_MATERIAL_DEFAULT, float border = 1);
& /** 创建一个链条状刚体 */
& static PhysicsBody* createEdgeChain(const Point* points, int count, const PhysicsMaterial& material = PHYSICSBODY_MATERIAL_DEFAULT, float border = 1);
& &添加一个shape &mass和moment赋值true
& virtual PhysicsShape* addShape(PhysicsShape* shape, bool addMassAndMoment = true);
& /*通过shape移除shape*/
& void removeShape(PhysicsShape* shape, bool reduceMassAndMoment = true);
& /*通过tag移除shape*/
& void removeShape(int tag, bool reduceMassAndMoment = true);
& /* 移除body的所有shape */
& void removeAllShapes(bool reduceMassAndMoment = true);
& /* 获取body的shapes */
& inline const Vector&PhysicsShape*&& getShapes() const { return _ }
& /* 获取第一个shape. */
& inline PhysicsShape* getFirstShape() const { return _shapes.size() &= 1 ? _shapes.at(0) : }
& /* 通过tag从body中获取shape */
& PhysicsShape* getShape(int tag)
& /**给body施加一个循序渐进的力,物体会受加速度影响,越来越快,像火车一样*/
& virtual void applyForce(const Vect& force);
& /** offset为偏移度 指碰到物体时 body旋转 偏移 一般设为默认值 值越大 旋转越快 偏移角度越大*/
& virtual void applyForce(const Vect& force, const Point& offset);
& /** 重置施加在body上的力 &清0了. */
& virtual void resetForces();
& /** 不会产生力,直接与body的速度叠加 产生新的速度. */
& virtual void applyImpulse(const Vect& impulse);
& /** Applies a continuous force to body. */
& virtual void applyImpulse(const Vect& impulse, const Point& offset);
& /**施加一个扭转力到刚体上 &就像向前翻转一块大石头一样. */
& virtual void applyTorque(float torque);
& /** 设置刚体的速度*/
& virtual void setVelocity(const Vect& velocity);
& /** 获取刚体的速度 */
& virtual Point getVelocity();
& /** 设置刚体角速度 就是单位时间内转动的弧度*/
& virtual void setAngularVelocity(float velocity);
& /** 通过一个局部点获取刚体的角速度*/
& virtual Point getVelocityAtLocalPoint(const Point& point);
& /** 通过世界点获取刚体的角速度*/
& virtual Point getVelocityAtWorldPoint(const Point& point);
& /** 获取刚体的角速度 */
& virtual float getAngularVelocity();
& /** 设置速度的极限值*/
& virtual void setVelocityLimit(float limit);
& /**获取速度的极限值 */
& virtual float getVelocityLimit();
& /** 设置角速度极限值 */
& virtual float getAngularVelocityLimit();
& /** 从world中移除body */
& void removeFromWorld();
& /** 获取world */
& inline PhysicsWorld* getWorld() const { return _ }
& /**获取body的所有关节 */
& inline const std::vector&PhysicsJoint*&& getJoints() const { return _ }
& /** 取得body设置的sprite. */
& inline Node* getNode() const { return _ }
& &* 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 0x (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);
& /** get the category bit mask */
& inline int getCategoryBitmask() const { return _categoryB }
& /** get the contact test bit mask */
& inline int getContactTestBitmask() const { return _contactTestB }
& /** get the collision bit mask */
& inline int getCollisionBitmask() const { return _collisionB }
& &* set the group of body
& &* Collision groups let you specify an integral group index. You can have all fixtures with the same group index always collide (positive index) or never collide (negative index)
& &* it have high priority than bit masks
& void setGroup(int group);
& /** get the group of body */
& inline int getGroup() const { return _ }
& /** 获取body坐标 */
& Point getPosition()
& /** 获取body角度. */
& float getRotation()
& /**判断body是否静止*/
& inline bool isDynamic() const { return _ }
& /**设置body状态 &false为静态 true为动态*/
& void setDynamic(bool dynamic);
& /**设置mass值 如果需要增加mass &有addmass方法 &不要在这里做加减 */
& void setMass(float mass);
& /** 取得mass. */
& inline float getMass() const { return _ }
add mass to body.
& &* if _mass(mass of the body) == PHYSICS_INFINITY, it remains.
& &* if mass == PHYSICS_INFINITY, _mass will be PHYSICS_INFINITY.
& &* if mass == -PHYSICS_INFINITY, _mass will not change.
& &* if mass + _mass &= 0, _mass will equal to MASS_DEFAULT(1.0)
& &* other wise, mass = mass + _
& void addMass(float mass);
set the body moment of inertia.
if you need add/subtract moment to body, don't use setMoment(getMoment() +/- moment), because the moment of body may be equal to PHYSICS_INFINITY, it will cause some unexpected result, please use addMoment() instead.
& void setMoment(float moment);
& /** get the body moment of inertia. */
& inline float getMoment(float moment) const { return _ }
add moment of inertia to body.
& &* if _moment(moment of the body) == PHYSICS_INFINITY, it remains.
& &* if moment == PHYSICS_INFINITY, _moment will be PHYSICS_INFINITY.
& &* if moment == -PHYSICS_INFINITY, _moment will not change.
& &* if moment + _moment &= 0, _moment will equal to MASS_DEFAULT(1.0)
& &* other wise, moment = moment + _
& void addMoment(float moment);
& /** 取得线性阻尼 */
& inline float getLinearDamping() const { return _linearD }
& &* 设置阻尼值
& &*它用来模拟body在气体或者液体中的摩擦力
& &*取值范围是 0.0f to 1.0f.&
& inline void setLinearDamping(float damping) { _linearDamping = }
& /** 获取角阻尼 */
& inline float getAngularDamping() const { return _angularD }
& &* 设置角阻尼
& &* 它用来模拟body在气体或者液体中的角阻尼
& &* the value is 0.0f to 1.0f.
& inline void setAngularDamping(float damping) { _angularDamping = }
& /** 判断body是否是 休息状态 */
& bool isResting()
& &*判断body能否在物理世界中模拟
& inline bool isEnabled() const { return _ }
& 设置body能否在物理世界中模拟
& void setEnable(bool enable);
& /** whether the body can rotation */
& inline bool isRotationEnabled() const { return _rotationE }
& /**设置能否旋转*/
& void setRotationEnable(bool enable);
& /** 判断body是否受引力影响 */
& inline bool isGravityEnabled() const { return _gravityE }
& /** 设置body是否受引力影响 */
& void setGravityEnable(bool enable);
& /** 取得body 的tag值 */
& inline int getTag() const { return _ }
& /** 设置body tag值*/
& inline void setTag(int tag) { _tag = }
& /** 转换 世界点 到 局部点 &类似 世界坐标和 局部坐标的转换*/
& Point world2Local(const Point& point);
& /** 转换局部坐标到 世界坐标 */
& Point local2World(const Point& point);
2.PhysicsShape
/** 通过shape 取得body */
& inline PhysicsBody* getBody() const { return _ }
& /** 返回shape的类型 */
& inline Type getType() const { return _ }
& /** return the area of this shape */
& inline float getArea() const { return _ }
& /** get moment */
& inline float getMoment() const { return _ }
& /** Set moment, it will change the body's moment this shape attaches */
& void setMoment(float moment);
& inline void setTag(int tag) { _tag = }
& inline int getTag() const { return _ }
& /**获取质量 */
& inline float getMass() const { return _ }
& /** Set mass, it will change the body's mass this shape attaches */
& void setMass(float mass);
& inline float getDensity() const { return _material. }//density为密度
& void setDensity(float density);//获取密度
& inline float getRestitution() const { return _material. }//获取弹性
& void setRestitution(float restitution);//设置弹性
& inline float getFriction() const { return _material. }//friction为摩擦力
& void setFriction(float friction);//设置摩擦力
& const PhysicsMaterial& getMaterial() const { return _ }//Material为材质
& void setMaterial(const PhysicsMaterial& material);设置材质
& /** Calculate the default moment value */
& virtual float calculateDefaultMoment() { return 0.0f; }
& /** Get offset */
& virtual Point getOffset() { return Point::ZERO; }
& /** Get center of this shape */
& virtual Point getCenter() { return getOffset(); }
& /** Test point is in shape or not */
& bool containsPoint(const Point& point)
& /** move the points to the center */
& static void recenterPoints(Point* points, int count, const Point& center = Point::ZERO);
& /** get center of the polyon points */
& static Point getPolyonCenter(const Point* points, int count);
& &* 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).
& inline void setCategoryBitmask(int bitmask) { _categoryBitmask = }
& inline int getCategoryBitmask() const { return _categoryB }
& &* 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 0x (all bits cleared).
& inline void setContactTestBitmask(int bitmask) { _contactTestBitmask = }
& inline int getContactTestBitmask() const { return _contactTestB }
& &* 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).
& inline void setCollisionBitmask(int bitmask) { _collisionBitmask = }
& inline int getCollisionBitmask() const { return _collisionB }
& void setGroup(int group);
& inline int getGroup() { return _ }
我在编写游戏的时候遇到了这个问题,& 物理引擎其他的内容还好理解,& 就这三个函数就是没找到有人详细的解释一下。& 我不知道这个都没弄明白,游戏是怎么做出来的。那我就不吐糟了,&&&&& 下面的所有内容都是我的个人推断。不知道正不正确。&&& 反正我目前是这么理解的。
我们先来看看这三个函数的定义:
/** &&&& * 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). &&&& */
/**定义了这个物理刚体是属于哪个类别的掩码。在一个场景中的每个物理刚体可以分配给达到 32 不同的类别(参数int bitmask是int类型4个字节32位),每个对应有32位中的1位掩码。您的游戏中您定义使用的掩码值。联同的 collisionBitMask 和 contactTestBitMask 的属性,定义哪些物理刚体彼此之间进行交互和何时你接收到这些交互作用的通知。默认值为的 0xFFFFFFFF (所有的位都被设置)。&&&& &&&& */ &&& inline void setCategoryBitmask(int bitmask) { _categoryBitmask = } &&& inline int getCategoryBitmask() const { return _categoryB } &&& /** &&&& * 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 0x (all bits cleared). &&&& */
&&& /** &&&&一个掩码,它定义了哪些类别的刚体与此物理刚体产生交集(相互作用)的通知。当两个刚体共有同一个空间时,通过执行逻辑与运算每个刚体的类别掩码被检测测试反对其他的刚体的接触掩码。如果任一比较结果在一个非零值,一个 PhysicsContact 对象被创建并传递到物理世界的委托。为获得最佳性能,仅设置您感兴趣的互动相互作用的接触掩码位。默认值为 0x (所有位均被清除)。 &&&& */ &&& inline void setContactTestBitmask(int bitmask) { _contactTestBitmask = } &&& inline int getContactTestBitmask() const { return _contactTestB } &&& /** &&&& * 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). &&&& */
一个掩码,它定义了哪些类别的物理刚体可以与这物理刚体发生碰撞。当两个物理刚体互相接触时,可能会发生冲突。这个刚体的碰撞掩码被相比其他刚体的类别掩码通过执行按位逻辑与运算。如果结果是一个非零值,则这一刚体被受碰撞。每个刚体独立地选择是否愿意受其他刚体的影响。例如,您可能会使用这来避免碰撞计算使对刚体的速度的变化可以忽略。默认值为的 0xFFFFFFFF (所有的位设置)。 &&&& */ &&& inline void setCollisionBitmask(int bitmask) { _collisionBitmask = } &&& inline int getCollisionBitmask() const { return _collisionB }
每个函数说了这么多,那么具体是什么意思呢?& 看看下面的例子:
box1-&getPhysicsBody()-&setCategoryBitmask(0x01); // 0001 box1-&getPhysicsBody()-&setContactTestBitmask(0x04); // 0100 box1-&getPhysicsBody()-&setCollisionBitmask(0x03); // 0011
box2-&getPhysicsBody()-&setCategoryBitmask(0x02); // 0010 box2-&getPhysicsBody()-&setContactTestBitmask(0x08); // 1000 box2-&getPhysicsBody()-&setCollisionBitmask(0x01); // 0001 box3-&getPhysicsBody()-&setCategoryBitmask(0x04); // 0100 box3-&getPhysicsBody()-&setContactTestBitmask(0x01); // 0001 box3-&getPhysicsBody()-&setCollisionBitmask(0x06); // 0110
&box1&和 box2 发生碰撞 &box1 box3& 不会 &box2 box3 也不会
为什么呢?&&& 解释如下:
box1的类别掩码 00
可接到通知&&&&&&&& 00
允许撞我&&&&&&&&& & 00
box2的类别掩码& 00
可接到通知&&&&&&&& 00
允许撞我 &&&&&&&&&&& 00
box3的类别掩码 &00
可接到通知&&&&&&&& &00
允许撞我&&&&&&&&&&& &00
现在做运算呗:
box1的允许撞我&&&&&00 &&& 与box2的类别掩码做按位与运算
box2的类别掩码&&&&&00
结果为:&&&&&&&&&&&&&&& 00 &&&&& 不为0,& box1会撞到box2撞到。
box2的允许撞我&&&&&00 &&& 与box1的类别掩码做按位与运算
box1的类别掩码&&&&&00
结果为:&&&&&&&&&&&&&&& 00 &&&&& 不为0,& box2会撞到box1撞到。
他们会相互受到撞击的。
box2的允许撞我与box3的类别掩码& 按位与运算为0;
box3的允许撞我与box2的类别掩码& 按位与运算为0;
box1的允许撞我与box3的类别掩码& 按位与运算为0;
box3的允许撞我与box1的类别掩码& 按位与运算为0;
box1 and box2 发生碰撞 but the box1 box3& 不会 the box2 box3 也不会
& 开源中国(OSChina.NET) |
开源中国社区(OSChina.net)是工信部
指定的官方社区

我要回帖

更多关于 skphysicsbody 的文章

 

随机推荐