From 4de7ef1515209edf0bd142abbeb6f92a58e3908b Mon Sep 17 00:00:00 2001 From: TheCodez Date: Wed, 20 Apr 2016 11:38:02 +0200 Subject: [PATCH] Fix setPhysicsBody method --- cocos/2d/CCNode.h | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/cocos/2d/CCNode.h b/cocos/2d/CCNode.h index 29a4bbf519..1b853bbe2f 100644 --- a/cocos/2d/CCNode.h +++ b/cocos/2d/CCNode.h @@ -38,6 +38,10 @@ #include "2d/CCComponentContainer.h" #include "2d/CCComponent.h" +#if CC_USE_PHYSICS +#include "physics/CCPhysicsBody.h" +#endif + NS_CC_BEGIN class GridBase; @@ -1940,9 +1944,9 @@ protected: ComponentContainer *_componentContainer; ///< Dictionary of components // opacity controls - GLubyte _displayedOpacity; + GLubyte _displayedOpacity; GLubyte _realOpacity; - Color3B _displayedColor; + Color3B _displayedColor; Color3B _realColor; bool _cascadeColorEnabled; bool _cascadeOpacityEnabled; @@ -1961,8 +1965,13 @@ protected: #if CC_USE_PHYSICS PhysicsBody* _physicsBody; public: - void setPhysicsBody(Component* physicsBody) - { + void setPhysicsBody(PhysicsBody* physicsBody) + { + if (_physicsBody != nullptr) + { + removeComponent(_physicsBody); + } + addComponent(physicsBody); } PhysicsBody* getPhysicsBody() const { return _physicsBody; }