From eccde9fe114990551f3e0a8e7c8e3283845ced52 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 19 Nov 2015 17:17:59 +0800 Subject: [PATCH] Fix PhysicsSprite not working with moveTo action issue --- extensions/physics-nodes/CCPhysicsSprite.cpp | 37 ++++++++++++++++---- extensions/physics-nodes/CCPhysicsSprite.h | 5 +++ 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/extensions/physics-nodes/CCPhysicsSprite.cpp b/extensions/physics-nodes/CCPhysicsSprite.cpp index 86080ad7aa..aaacbfa89b 100644 --- a/extensions/physics-nodes/CCPhysicsSprite.cpp +++ b/extensions/physics-nodes/CCPhysicsSprite.cpp @@ -195,6 +195,12 @@ float PhysicsSprite::getPositionY() const return getPosFromPhysics().y; } +Vec3 PhysicsSprite::getPosition3D() const +{ + Vec2 pos = getPosFromPhysics(); + return Vec3(pos.x, pos.y, 0); +} + // // Chipmunk only // @@ -280,19 +286,38 @@ const Vec2& PhysicsSprite::getPosFromPhysics() const return s_physicPosion; } -void PhysicsSprite::setPosition(const Vec2 &pos) +void PhysicsSprite::setPosition(float x, float y) { #if CC_ENABLE_CHIPMUNK_INTEGRATION - - cpVect cpPos = cpv(pos.x, pos.y); + + cpVect cpPos = cpv(x, y); cpBodySetPos(_CPBody, cpPos); - + #elif CC_ENABLE_BOX2D_INTEGRATION - + float angle = _pB2Body->GetAngle(); - _pB2Body->SetTransform(b2Vec2(pos.x / _PTMRatio, pos.y / _PTMRatio), angle); + _pB2Body->SetTransform(b2Vec2(x / _PTMRatio, y / _PTMRatio), angle); #endif +} +void PhysicsSprite::setPosition(const Vec2 &pos) +{ + setPosition(pos.x, pos.y); +} + +void PhysicsSprite::setPositionX(float x) +{ + setPosition(x, getPositionY()); +} + +void PhysicsSprite::setPositionY(float y) +{ + setPosition(getPositionX(), y); +} + +void PhysicsSprite::setPosition3D(const Vec3& position) +{ + setPosition(position.x, position.y); } float PhysicsSprite::getRotation() const diff --git a/extensions/physics-nodes/CCPhysicsSprite.h b/extensions/physics-nodes/CCPhysicsSprite.h index ae17b824a0..b8016f2681 100644 --- a/extensions/physics-nodes/CCPhysicsSprite.h +++ b/extensions/physics-nodes/CCPhysicsSprite.h @@ -116,7 +116,12 @@ public: virtual void getPosition(float* x, float* y) const override; virtual float getPositionX() const override; virtual float getPositionY() const override; + virtual Vec3 getPosition3D() const override; virtual void setPosition(const Vec2 &position) override; + virtual void setPosition(float x, float y) override; + virtual void setPositionX(float x) override; + virtual void setPositionY(float y) override; + virtual void setPosition3D(const Vec3& position) override; virtual float getRotation() const override; virtual void setRotation(float fRotation) override;