From 19b66049b3dac7aabf9b741b633d10ec5f358f14 Mon Sep 17 00:00:00 2001 From: Rohan Kuruvilla Date: Tue, 19 Mar 2013 23:25:30 -0700 Subject: [PATCH] Fixing issues with rotationX, rotationY in CCBuilderReader --- extensions/CCBReader/CCBAnimationManager.cpp | 139 +++++++++++++++++-- extensions/CCBReader/CCBAnimationManager.h | 10 +- extensions/CCBReader/CCNodeLoader.cpp | 7 +- extensions/CCBReader/CCNodeLoader.h | 2 + 4 files changed, 145 insertions(+), 13 deletions(-) diff --git a/extensions/CCBReader/CCBAnimationManager.cpp b/extensions/CCBReader/CCBAnimationManager.cpp index d4dd0a1854..fd8d88e3af 100644 --- a/extensions/CCBReader/CCBAnimationManager.cpp +++ b/extensions/CCBReader/CCBAnimationManager.cpp @@ -286,12 +286,7 @@ CCActionInterval* CCBAnimationManager::getAction(CCBKeyframe *pKeyframe0, CCBKey { float duration = pKeyframe1->getTime() - (pKeyframe0 ? pKeyframe0->getTime() : 0); - if (strcmp(pPropName, "rotation") == 0) - { - CCBValue *value = (CCBValue*)pKeyframe1->getValue(); - return CCBRotateTo::create(duration, value->getFloatValue()); - } - else if(strcmp(pPropName, "rotationX") == 0) + if (strcmp(pPropName, "rotationX") == 0) { CCBValue *value = (CCBValue*)pKeyframe1->getValue(); return CCBRotateXTo::create(duration, value->getFloatValue()); @@ -301,6 +296,11 @@ CCActionInterval* CCBAnimationManager::getAction(CCBKeyframe *pKeyframe0, CCBKey CCBValue *value = (CCBValue*)pKeyframe1->getValue(); return CCBRotateYTo::create(duration, value->getFloatValue()); } + else if (strcmp(pPropName, "rotation") == 0) + { + CCBValue *value = (CCBValue*)pKeyframe1->getValue(); + return CCBRotateTo::create(duration, value->getFloatValue()); + } else if (strcmp(pPropName, "opacity") == 0) { CCBValue *value = (CCBValue*)pKeyframe1->getValue(); @@ -448,6 +448,14 @@ void CCBAnimationManager::setAnimatedProperty(const char *pPropName, CCNode *pNo { float rotate = ((CCBValue*)pValue)->getFloatValue(); pNode->setRotation(rotate); + } else if(strcmp(pPropName, "rotationX") == 0) + { + float rotate = ((CCBValue*)pValue)->getFloatValue(); + pNode->setRotationX(rotate); + }else if(strcmp(pPropName, "rotationY") == 0) + { + float rotate = ((CCBValue*)pValue)->getFloatValue(); + pNode->setRotationY(rotate); } else if (strcmp(pPropName, "opacity") == 0) { @@ -1052,13 +1060,68 @@ void CCBRotateTo::update(float time) ************************************************************/ +CCBRotateXTo* CCBRotateXTo::create(float fDuration, float fAngle) +{ + CCBRotateXTo *ret = new CCBRotateXTo(); + if (ret) + { + if (ret->initWithDuration(fDuration, fAngle)) + { + ret->autorelease(); + } + else + { + CC_SAFE_DELETE(ret); + } + } + + return ret; +} + +bool CCBRotateXTo::initWithDuration(float fDuration, float fAngle) +{ + if (CCActionInterval::initWithDuration(fDuration)) + { + mDstAngle = fAngle; + + return true; + } + else + { + return false; + } +} + + void CCBRotateXTo::startWithTarget(CCNode *pNode) { - CCActionInterval::startWithTarget(pNode); - mStartAngle = m_pTarget->getRotation(); + //CCActionInterval::startWithTarget(pNode); + m_pOriginalTarget = pNode; + m_pTarget = pNode; + m_elapsed = 0.0f; + m_bFirstTick = true; + mStartAngle = m_pTarget->getRotationX(); mDiffAngle = mDstAngle - mStartAngle; } +CCObject* CCBRotateXTo::copyWithZone(CCZone *pZone) +{ + CCZone *pNewZone = NULL; + CCBRotateXTo *pRet = NULL; + + if (pZone && pZone->m_pCopyObject) { + pRet = (CCBRotateXTo*) (pZone->m_pCopyObject); + } else { + pRet = new CCBRotateXTo(); + pZone = pNewZone = new CCZone(pRet); + } + + pRet->initWithDuration(m_fDuration, mDstAngle); + CCActionInterval::copyWithZone(pZone); + CC_SAFE_DELETE(pNewZone); + return pRet; +} + void CCBRotateXTo::update(float time) { m_pTarget->setRotationX(mStartAngle + (mDiffAngle * time)) @@ -1073,13 +1136,69 @@ void CCBRotateXTo::update(float time) +CCBRotateYTo* CCBRotateYTo::create(float fDuration, float fAngle) +{ + CCBRotateYTo *ret = new CCBRotateYTo(); + if (ret) + { + if (ret->initWithDuration(fDuration, fAngle)) + { + ret->autorelease(); + } + else + { + CC_SAFE_DELETE(ret); + } + } + + return ret; +} + +bool CCBRotateYTo::initWithDuration(float fDuration, float fAngle) +{ + if (CCActionInterval::initWithDuration(fDuration)) + { + mDstAngle = fAngle; + + return true; + } + else + { + return false; + } +} + + void CCBRotateYTo::startWithTarget(CCNode *pNode) { - CCActionInterval::startWithTarget(pNode); - mStartAngle = m_pTarget->getRotation(); + // CCActionInterval::startWithTarget(pNode); + m_pOriginalTarget = pNode; + m_pTarget = pNode; + m_elapsed = 0.0f; + m_bFirstTick = true; + mStartAngle = m_pTarget->getRotationY(); mDiffAngle = mDstAngle - mStartAngle; } + +CCObject* CCBRotateYTo::copyWithZone(CCZone *pZone) +{ + CCZone *pNewZone = NULL; + CCBRotateYTo *pRet = NULL; + + if (pZone && pZone->m_pCopyObject) { + pRet = (CCBRotateYTo*) (pZone->m_pCopyObject); + } else { + pRet = new CCBRotateYTo(); + pZone = pNewZone = new CCZone(pRet); + } + + pRet->initWithDuration(m_fDuration, mDstAngle); + CCActionInterval::copyWithZone(pZone); + CC_SAFE_DELETE(pNewZone); + return pRet; +} + void CCBRotateYTo::update(float time) { m_pTarget->setRotationY(mStartAngle + (mDiffAngle * time)) diff --git a/extensions/CCBReader/CCBAnimationManager.h b/extensions/CCBReader/CCBAnimationManager.h index 28d4064400..f702677801 100644 --- a/extensions/CCBReader/CCBAnimationManager.h +++ b/extensions/CCBReader/CCBAnimationManager.h @@ -176,25 +176,31 @@ public: }; -class CCBRotateXTo: public CCBRotateTo { +class CCBRotateXTo: public CCActionInterval { private: float mStartAngle; float mDstAngle; float mDiffAngle; public: + static CCBRotateXTo* create(float fDuration, float fAngle); + bool initWithDuration(float fDuration, float fAngle); virtual void startWithTarget(CCNode *pNode); + virtual CCObject* copyWithZone(CCZone *pZone); virtual void update(float time); }; -class CCBRotateYTo: public CCBRotateTo { +class CCBRotateYTo: public CCActionInterval { private: float mStartAngle; float mDstAngle; float mDiffAngle; public: + static CCBRotateYTo* create(float fDuration, float fAngle); + bool initWithDuration(float fDuration, float fAngle); virtual void startWithTarget(CCNode *pNode); + virtual CCObject* copyWithZone(CCZone *pZone); virtual void update(float time); }; diff --git a/extensions/CCBReader/CCNodeLoader.cpp b/extensions/CCBReader/CCNodeLoader.cpp index 8d853bdea8..ab80074733 100644 --- a/extensions/CCBReader/CCNodeLoader.cpp +++ b/extensions/CCBReader/CCNodeLoader.cpp @@ -965,7 +965,12 @@ void CCNodeLoader::onHandlePropTypeFloat(CCNode * pNode, CCNode * pParent, const void CCNodeLoader::onHandlePropTypeDegrees(CCNode * pNode, CCNode * pParent, const char* pPropertyName, float pDegrees, CCBReader * pCCBReader) { if(strcmp(pPropertyName, PROPERTY_ROTATION) == 0) { pNode->setRotation(pDegrees); - } else { + } else if(strcmp(pPropertyName, PROPERTY_ROTATIONX) == 0) { + pNode->setRotationX(pDegrees); + } else if(strcmp(pPropertyName, PROPERTY_ROTATIONY) == 0) { + pNode->setRotationY(pDegrees); + } + else { ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName); } } diff --git a/extensions/CCBReader/CCNodeLoader.h b/extensions/CCBReader/CCNodeLoader.h index 1644dc35a8..1390a3872e 100644 --- a/extensions/CCBReader/CCNodeLoader.h +++ b/extensions/CCBReader/CCNodeLoader.h @@ -14,6 +14,8 @@ NS_CC_EXT_BEGIN #define PROPERTY_ANCHORPOINT "anchorPoint" #define PROPERTY_SCALE "scale" #define PROPERTY_ROTATION "rotation" +#define PROPERTY_ROTATIONX "rotationX" +#define PROPERTY_ROTATIONY "rotationY" #define PROPERTY_TAG "tag" #define PROPERTY_IGNOREANCHORPOINTFORPOSITION "ignoreAnchorPointForPosition" #define PROPERTY_VISIBLE "visible"