本文来自http://blog.csdn.net/runaying ,引用必须注明出处!
cocos2d-x节点(CCPhysicsWorld.h)API
温馨提醒:为了大家能更好学习,强烈推荐大家看看本人的这篇博客 Cocos2d-X权威指南笔记
//添加移除物理世界关联
///cocos2d-x-3.0alpha0/cocos2dx/physics //添加移除物理世界关联 #include "CCPhysicsSetting.h" #ifdef CC_USE_PHYSICS #ifndef __CCPHYSICS_WORLD_H__ #define __CCPHYSICS_WORLD_H__ #include "cocoa/CCObject.h" #include "cocoa/CCGeometry.h" #if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) typedef struct cpArbiter cpArbiter; typedef struct cpSpace cpSpace; #endif NS_CC_BEGIN class PhysicsBody; class PhysicsJoint; class PhysicsWorldInfo; class PhysicsShape; class PhysicsContact; class PhysicsContactPreSolve; class PhysicsContactPostSolve; class PhysicsContactListener; class Array; class Sprite; class Scene; class DrawNode; /** * @brief 一个PhysicsWorld对象模拟碰撞等物理属性. 你不应该直接创建 PhysicsWorld 对象; 相反,你可以从一个 Scene 对象里面得到它. */ class PhysicsWorld { public: /** 添加一个物理世界的关联.*/ void addJoint(PhysicsJoint* joint); /** 移除一个物理世界的关联.*/ void removeJoint(PhysicsJoint* joint); /** 移除所有物理世界的关联.*/ void removeAllJoints(); Array* getBodysAlongRay(Point start, Point end) const; Array* getBodysAtPoint(Point point) const; Array* getBodysInRect(Rect rect) const; Array* getAllBody() const; /** 注册一个侦听器接收联系回调*/ inline void registerContactListener(PhysicsContactListener* delegate) { _listener = delegate; } /** 注销一个监听器. */ inline void unregisterContactListener() { _listener = nullptr; } /** get 重力值 */ inline Point getGravity() { return _gravity; } /** set 重力值 */ void setGravity(Point gravity); /** 启用测试调试 draw */ inline bool isDebugDraw() { return _debugDraw; } /** 设置调试 draw */ inline void setDebugDraw(bool debugDraw) { _debugDraw = debugDraw; } protected: static PhysicsWorld* create(); bool init(); void setScene(Scene* scene); virtual void addChild(PhysicsBody* body); virtual void addShape(PhysicsShape* shape); virtual void update(float delta); virtual void debugDraw(); virtual void drawWithShape(DrawNode* node, PhysicsShape* shape); virtual int collisionBeginCallback(const PhysicsContact& contact); virtual int collisionPreSolveCallback(const PhysicsContact& contact, const PhysicsContactPreSolve& solve); virtual void collisionPostSolveCallback(const PhysicsContact& contact, const PhysicsContactPostSolve& solve); virtual void collisionSeparateCallback(const PhysicsContact& contact); #if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) static int collisionBeginCallbackFunc(cpArbiter *arb, struct cpSpace *space, void *data); static int collisionPreSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); static void collisionPostSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); static void collisionSeparateCallbackFunc(cpArbiter *arb, cpSpace *space, void *data); #endif protected: Point _gravity; float _speed; PhysicsWorldInfo* _info; PhysicsContactListener* _listener; Array* _bodys; Scene* _scene; bool _debugDraw; DrawNode* _drawNode; protected: PhysicsWorld(); virtual ~PhysicsWorld(); friend class Sprite; friend class Scene; friend class PhysicsBody; }; NS_CC_END #endif // __CCPHYSICS_WORLD_H__ #endif // CC_USE_PHYSICS