Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions cocos/2d/CCNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/CCNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,7 @@ class CC_DLL Node : public Object
/**
* update rotation and position from physics body
*/
virtual void updatePhysicsTransform();
virtual bool updatePhysicsTransform();

#endif

Expand Down
6 changes: 4 additions & 2 deletions cocos/2d/CCSprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down