diff --git a/cocos/2d/CCNode.cpp b/cocos/2d/CCNode.cpp index c665b254b41d..bdff745edf5f 100644 --- a/cocos/2d/CCNode.cpp +++ b/cocos/2d/CCNode.cpp @@ -1341,14 +1341,17 @@ Point Node::convertTouchToNodeSpaceAR(Touch *touch) const } #ifdef CC_USE_PHYSICS -void Node::updatePhysicsTransform() +bool Node::updatePhysicsTransform() { - if (_physicsBody) + if (_physicsBody != nullptr && _physicsBody->getWorld() != nullptr && !_physicsBody->isResting()) { _position = _physicsBody->getPosition(); _rotationX = _rotationY = _physicsBody->getRotation(); _transformDirty = _inverseDirty = true; + return true; } + + return false; } #endif diff --git a/cocos/2d/CCNode.h b/cocos/2d/CCNode.h index 921267666925..1beda38d4c53 100644 --- a/cocos/2d/CCNode.h +++ b/cocos/2d/CCNode.h @@ -1386,7 +1386,7 @@ class CC_DLL Node : public Object /** * update rotation and position from physics body */ - virtual void updatePhysicsTransform(); + virtual bool updatePhysicsTransform(); #endif diff --git a/cocos/2d/CCSprite.cpp b/cocos/2d/CCSprite.cpp index b4be678d87e2..36577238b0f5 100644 --- a/cocos/2d/CCSprite.cpp +++ b/cocos/2d/CCSprite.cpp @@ -496,8 +496,10 @@ void Sprite::updateTransform(void) CCASSERT(_batchNode, "updateTransform is only valid when Sprite is being rendered using an SpriteBatchNode"); #ifdef CC_USE_PHYSICS - updatePhysicsTransform(); - setDirty(true); + if (updatePhysicsTransform()) + { + setDirty(true); + }; #endif // recalculate matrix only if it is dirty