Merge pull request #6359 from pandamicro/NewPhysicsSpriteFix

Fixed #4755: Fix PhysicsSprite transform not updated issue
This commit is contained in:
James Chen 2014-04-25 10:36:46 +08:00
commit 45cc122074
2 changed files with 37 additions and 22 deletions

View File

@ -328,8 +328,7 @@ void PhysicsSprite::setRotation(float fRotation)
} }
// returns the transform matrix according the Chipmunk Body values void PhysicsSprite::syncPhysicsTransform() const
const kmMat4& PhysicsSprite::getNodeToParentTransform() const
{ {
// Although scale is not used by physics engines, it is calculated just in case // Although scale is not used by physics engines, it is calculated just in case
// the sprite is animated (scaled up/down) using actions. // the sprite is animated (scaled up/down) using actions.
@ -356,9 +355,6 @@ const kmMat4& PhysicsSprite::getNodeToParentTransform() const
kmMat4Fill(&_transform, mat); kmMat4Fill(&_transform, mat);
return _transform;
#elif CC_ENABLE_BOX2D_INTEGRATION #elif CC_ENABLE_BOX2D_INTEGRATION
b2Vec2 pos = _pB2Body->GetPosition(); b2Vec2 pos = _pB2Body->GetPosition();
@ -392,9 +388,25 @@ const kmMat4& PhysicsSprite::getNodeToParentTransform() const
kmMat4Fill(&_transform, mat); kmMat4Fill(&_transform, mat);
return _transform;
#endif #endif
} }
// returns the transform matrix according the Chipmunk Body values
const kmMat4& PhysicsSprite::getNodeToParentTransform() const
{
syncPhysicsTransform();
return _transform;
}
void PhysicsSprite::draw(Renderer *renderer, const kmMat4 &transform, bool transformUpdated)
{
if (isDirty())
{
syncPhysicsTransform();
}
Sprite::draw(renderer, _transform, transformUpdated);
}
NS_CC_EXT_END NS_CC_EXT_END

View File

@ -112,8 +112,11 @@ public:
virtual void setPosition(const Point &position) override; virtual void setPosition(const Point &position) override;
virtual float getRotation() const override; virtual float getRotation() const override;
virtual void setRotation(float fRotation) override; virtual void setRotation(float fRotation) override;
virtual void syncPhysicsTransform() const;
virtual const kmMat4& getNodeToParentTransform() const override; virtual const kmMat4& getNodeToParentTransform() const override;
virtual void draw(Renderer *renderer, const kmMat4 &transform, bool transformUpdated) override;
protected: protected:
const Point& getPosFromPhysics() const; const Point& getPosFromPhysics() const;