diff --git a/cocos2dx/actions/CCActionCamera.cpp b/cocos2dx/actions/CCActionCamera.cpp index 45b5ba521c..9a90393629 100644 --- a/cocos2dx/actions/CCActionCamera.cpp +++ b/cocos2dx/actions/CCActionCamera.cpp @@ -23,12 +23,14 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ + #include "CCActionCamera.h" #include "base_nodes/CCNode.h" #include "CCCamera.h" #include "CCStdC.h" #include "cocoa/CCZone.h" + NS_CC_BEGIN // // CameraAction @@ -50,9 +52,9 @@ CCActionCamera* CCActionCamera::clone() const return a; } -CCReverseTime * CCActionCamera::reverse() const +CCFiniteTimeAction * CCActionCamera::reverse() const { - return CCReverseTime::create(this); + return CCReverseTime::create(const_cast(this)); } // // CCOrbitCamera diff --git a/cocos2dx/actions/CCActionCamera.h b/cocos2dx/actions/CCActionCamera.h index 03a28334de..f2c7463eba 100644 --- a/cocos2dx/actions/CCActionCamera.h +++ b/cocos2dx/actions/CCActionCamera.h @@ -59,9 +59,9 @@ public: // super methods virtual void startWithTarget(CCNode *pTarget); /** returns a new reversed action */ - virtual CCReverseTime * reverse() const; + virtual CCFiniteTimeAction * reverse() const; /** returns a new clone of the action */ - CCActionCamera *clone() const; + virtual CCActionCamera *clone() const; protected: float m_fCenterXOrig; float m_fCenterYOrig; diff --git a/cocos2dx/actions/CCActionGrid.cpp b/cocos2dx/actions/CCActionGrid.cpp index 80759c35f4..ab2a56a8c3 100644 --- a/cocos2dx/actions/CCActionGrid.cpp +++ b/cocos2dx/actions/CCActionGrid.cpp @@ -75,6 +75,11 @@ void CCGridAction::startWithTarget(CCNode *pTarget) } } +CCGridAction* CCGridAction::reverse() const +{ + return (CCGridAction*)CCReverseTime::create( this->clone() ); +} + CCGridBase* CCGridAction::getGrid(void) { // Abstract class needs implementation @@ -199,7 +204,7 @@ void CCAccelDeccelAmplitude::update(float time) ((CCAccelDeccelAmplitude*)(m_pOther))->setAmplitudeRate(powf(f, m_fRate)); } -CCAccelDeccelAmplitude* CCAccelDeccelAmplitude::reverse(void) const +CCAccelDeccelAmplitude* CCAccelDeccelAmplitude::reverse() const { return CCAccelDeccelAmplitude::create(m_pOther->reverse(), m_fDuration); } @@ -263,7 +268,7 @@ void CCAccelAmplitude::update(float time) m_pOther->update(time); } -CCAccelAmplitude* CCAccelAmplitude::reverse(void) const +CCAccelAmplitude* CCAccelAmplitude::reverse() const { return CCAccelAmplitude::create(m_pOther->reverse(), m_fDuration); } @@ -320,7 +325,7 @@ void CCDeccelAmplitude::update(float time) m_pOther->update(time); } -CCDeccelAmplitude* CCDeccelAmplitude::reverse(void) const +CCDeccelAmplitude* CCDeccelAmplitude::reverse() const { return CCDeccelAmplitude::create(m_pOther->reverse(), m_fDuration); } diff --git a/cocos2dx/actions/CCActionGrid.h b/cocos2dx/actions/CCActionGrid.h index d2d3bbe1b7..eec6f3f0f4 100644 --- a/cocos2dx/actions/CCActionGrid.h +++ b/cocos2dx/actions/CCActionGrid.h @@ -43,8 +43,11 @@ class CC_DLL CCGridAction : public CCActionInterval public: /** returns a new clone of the action */ virtual CCGridAction * clone() const = 0; - /** returns a new reversed action */ - virtual CCGridAction* reverse(void) const = 0; + + /** returns a new reversed action. + The reversed action is created with the CCReverseTime action. + */ + virtual CCGridAction* reverse() const; virtual void startWithTarget(CCNode *pTarget); diff --git a/cocos2dx/actions/CCActionInterval.cpp b/cocos2dx/actions/CCActionInterval.cpp index 962706189e..bd45f73f93 100644 --- a/cocos2dx/actions/CCActionInterval.cpp +++ b/cocos2dx/actions/CCActionInterval.cpp @@ -1449,7 +1449,7 @@ void CCJumpBy::update(float t) } } -CCActionInterval* CCJumpBy::reverse(void) +CCJumpBy* CCJumpBy::reverse() const { return CCJumpBy::create(m_fDuration, ccp(-m_delta.x, -m_delta.y), m_height, m_nJumps); @@ -1844,7 +1844,7 @@ void CCScaleBy::startWithTarget(CCNode *pTarget) m_fDeltaY = m_fStartScaleY * m_fEndScaleY - m_fStartScaleY; } -CCActionInterval* CCScaleBy::reverse(void) +CCScaleBy* CCScaleBy::reverse() const { return CCScaleBy::create(m_fDuration, 1 / m_fEndScaleX, 1 / m_fEndScaleY); } @@ -1985,7 +1985,7 @@ void CCFadeIn::update(float time) /*m_pTarget->setOpacity((GLubyte)(255 * time));*/ } -CCActionInterval* CCFadeIn::reverse(void) +CCActionInterval* CCFadeIn::reverse() const { return CCFadeOut::create(m_fDuration); } @@ -2043,7 +2043,7 @@ void CCFadeOut::update(float time) /*m_pTarget->setOpacity(GLubyte(255 * (1 - time)));*/ } -CCActionInterval* CCFadeOut::reverse(void) +CCActionInterval* CCFadeOut::reverse() const { return CCFadeIn::create(m_fDuration); } @@ -2284,7 +2284,7 @@ void CCTintBy::update(float time) } } -CCActionInterval* CCTintBy::reverse(void) +CCTintBy* CCTintBy::reverse() const { return CCTintBy::create(m_fDuration, -m_deltaR, -m_deltaG, -m_deltaB); } @@ -2337,7 +2337,7 @@ void CCDelayTime::update(float time) return; } -CCActionInterval* CCDelayTime::reverse(void) +CCDelayTime* CCDelayTime::reverse() const { return CCDelayTime::create(m_fDuration); } @@ -2350,7 +2350,7 @@ CCReverseTime* CCReverseTime::create(CCFiniteTimeAction *pAction) { // casting to prevent warnings CCReverseTime *pReverseTime = new CCReverseTime(); - pReverseTime->initWithAction(pAction); + pReverseTime->initWithAction( pAction->clone() ); pReverseTime->autorelease(); return pReverseTime; @@ -2378,7 +2378,7 @@ bool CCReverseTime::initWithAction(CCFiniteTimeAction *pAction) CCReverseTime* CCReverseTime::clone(void) const { auto a = new CCReverseTime(*this); - a->initWithAction((CCFiniteTimeAction*)m_pOther->clone()); + a->initWithAction( m_pOther->clone() ); a->autorelease(); return a; } @@ -2436,7 +2436,7 @@ void CCReverseTime::update(float time) } } -CCReverseTime* CCReverseTime::reverse(void) const +CCFiniteTimeAction* CCReverseTime::reverse() const { return m_pOther->clone(); } diff --git a/cocos2dx/actions/CCActionInterval.h b/cocos2dx/actions/CCActionInterval.h index 2aa7376eeb..5bd8a4ffcd 100644 --- a/cocos2dx/actions/CCActionInterval.h +++ b/cocos2dx/actions/CCActionInterval.h @@ -282,9 +282,13 @@ public: virtual bool initWithDuration(float fDuration, float fDeltaAngleX, float fDeltaAngleY); virtual CCObject* copyWithZone(CCZone* pZone); + /** returns a new clone of the action */ virtual CCRotateTo* clone() const; + /** returns a new reversed action */ + virtual CCRotateTo* reverse() const; + virtual void startWithTarget(CCNode *pTarget); virtual void update(float time); @@ -645,7 +649,7 @@ public: /** returns a new clone of the action */ virtual CCFadeIn* clone() const; /** returns a new reversed action */ - virtual CCFadeIn* reverse(void) const; + virtual CCActionInterval* reverse(void) const; virtual CCObject* copyWithZone(CCZone* pZone); @@ -665,7 +669,7 @@ public: /** returns a new clone of the action */ virtual CCFadeOut* clone() const; /** returns a new reversed action */ - virtual CCFadeOut* reverse(void) const; + virtual CCActionInterval* reverse(void) const; public: @@ -793,7 +797,7 @@ public: bool initWithAction(CCFiniteTimeAction *pAction); /** returns a new reversed action */ - virtual CCReverseTime* reverse(void) const; + virtual CCFiniteTimeAction* reverse() const; /** returns a new clone of the action */ virtual CCReverseTime* clone() const; virtual CCObject* copyWithZone(CCZone* pZone); diff --git a/cocos2dx/actions/CCActionTiledGrid.h b/cocos2dx/actions/CCActionTiledGrid.h index faf53ae1dd..a1fa6702fd 100644 --- a/cocos2dx/actions/CCActionTiledGrid.h +++ b/cocos2dx/actions/CCActionTiledGrid.h @@ -44,9 +44,6 @@ public: /** returns a new clone of the action */ virtual CCShakyTiles3D* clone() const; - /** returns a new reversed action */ - virtual CCShakyTiles3D* reverse() const; - virtual CCObject* copyWithZone(CCZone* pZone); virtual void update(float time); @@ -70,9 +67,6 @@ public: /** returns a new clone of the action */ virtual CCShatteredTiles3D* clone() const; - /** returns a new reversed action */ - virtual CCShatteredTiles3D* reverse() const; - virtual CCObject* copyWithZone(CCZone* pZone); virtual void update(float time); @@ -106,9 +100,6 @@ public: /** returns a new clone of the action */ virtual CCShuffleTiles* clone() const; - /** returns a new reversed action */ - virtual CCShuffleTiles* reverse() const; - virtual CCObject* copyWithZone(CCZone* pZone); public: @@ -136,9 +127,6 @@ public: /** returns a new clone of the action */ virtual CCFadeOutTRTiles* clone() const; - /** returns a new reversed action */ - virtual CCFadeOutTRTiles* reverse() const; - public: /** creates the action with the grid size and the duration */ @@ -156,9 +144,6 @@ public: /** returns a new clone of the action */ virtual CCFadeOutBLTiles* clone() const; - /** returns a new reversed action */ - virtual CCFadeOutBLTiles* reverse() const; - public: /** creates the action with the grid size and the duration */ @@ -177,9 +162,6 @@ public: /** returns a new clone of the action */ virtual CCFadeOutUpTiles* clone() const; - /** returns a new reversed action */ - virtual CCFadeOutUpTiles* reverse() const; - public: /** creates the action with the grid size and the duration */ static CCFadeOutUpTiles* create(float duration, const CCSize& gridSize); @@ -195,9 +177,6 @@ public: /** returns a new clone of the action */ virtual CCFadeOutDownTiles* clone() const; - /** returns a new reversed action */ - virtual CCFadeOutDownTiles* reverse() const; - virtual float testFunc(const CCSize& pos, float time); public: @@ -222,9 +201,6 @@ public: /** returns a new clone of the action */ virtual CCTurnOffTiles* clone() const; - /** returns a new reversed action */ - virtual CCTurnOffTiles* reverse() const; - virtual CCObject* copyWithZone(CCZone* pZone); virtual void startWithTarget(CCNode *pTarget); virtual void update(float time); @@ -260,9 +236,6 @@ public: /** returns a new clone of the action */ virtual CCWavesTiles3D* clone() const; - /** returns a new reversed action */ - virtual CCWavesTiles3D* reverse() const; - virtual CCObject* copyWithZone(CCZone* pZone); virtual void update(float time); @@ -295,9 +268,6 @@ public: /** returns a new clone of the action */ virtual CCJumpTiles3D* clone() const; - /** returns a new reversed action */ - virtual CCJumpTiles3D* reverse() const; - virtual CCObject* copyWithZone(CCZone* pZone); virtual void update(float time); @@ -321,9 +291,6 @@ public : /** returns a new clone of the action */ virtual CCSplitRows* clone() const; - /** returns a new reversed action */ - virtual CCSplitRows* reverse() const; - virtual CCObject* copyWithZone(CCZone* pZone); virtual void update(float time); virtual void startWithTarget(CCNode *pTarget); @@ -347,9 +314,6 @@ public: /** returns a new clone of the action */ virtual CCSplitCols* clone() const; - /** returns a new reversed action */ - virtual CCSplitCols* reverse() const; - virtual CCObject* copyWithZone(CCZone* pZone); virtual void update(float time); virtual void startWithTarget(CCNode *pTarget); diff --git a/extensions/CCBReader/CCBAnimationManager.h b/extensions/CCBReader/CCBAnimationManager.h index ad8b755155..959e8f1b94 100644 --- a/extensions/CCBReader/CCBAnimationManager.h +++ b/extensions/CCBReader/CCBAnimationManager.h @@ -141,6 +141,10 @@ public: virtual void update(float time); /** returns a new clone of the action */ virtual CCBSetSpriteFrame* clone() const; + + /** returns a new reversed action */ + virtual CCBSetSpriteFrame* reverse() const; + virtual CCObject* copyWithZone(CCZone *pZone); }; @@ -160,6 +164,10 @@ public: virtual void update(float time); /** returns a new clone of the action */ virtual CCBSoundEffect* clone() const; + + /** returns a new reversed action */ + virtual CCBSoundEffect* reverse() const; + virtual CCObject* copyWithZone(CCZone *pZone); }; @@ -177,6 +185,10 @@ public: virtual void update(float time); /** returns a new clone of the action */ virtual CCBRotateTo* clone() const; + + /** returns a new reversed action */ + virtual CCBRotateTo* reverse() const; + virtual CCObject* copyWithZone(CCZone *pZone); virtual void startWithTarget(CCNode *pNode); }; @@ -193,6 +205,10 @@ public: virtual void startWithTarget(CCNode *pNode); /** returns a new clone of the action */ virtual CCBRotateXTo* clone() const; + + /** returns a new reversed action */ + virtual CCBRotateXTo* reverse() const; + virtual CCObject* copyWithZone(CCZone *pZone); virtual void update(float time); }; @@ -210,6 +226,10 @@ public: virtual void startWithTarget(CCNode *pNode); /** returns a new clone of the action */ virtual CCBRotateYTo* clone() const; + + /** returns a new reversed action */ + virtual CCBRotateYTo* reverse() const; + virtual CCObject* copyWithZone(CCZone *pZone); virtual void update(float time); }; @@ -222,6 +242,9 @@ public: /** returns a new clone of the action */ virtual CCBEaseInstant* clone() const; + + /** returns a new reversed action */ + virtual CCBEaseInstant* reverse() const; virtual void update(float dt); }; diff --git a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp index 5c86c33725..d106d31c4b 100644 --- a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp @@ -1164,8 +1164,8 @@ void ActionReverseSequence2::onEnter() // Sequence should work both with IntervalAction and InstantActions CCActionInterval* move1 = CCMoveBy::create(1, ccp(250,0)); CCActionInterval* move2 = CCMoveBy::create(1, ccp(0,50)); - CCToggleVisibility* tog1 = new CCToggleVisibility(); - CCToggleVisibility* tog2 = new CCToggleVisibility(); + CCToggleVisibility* tog1 = CCToggleVisibility::create(); + CCToggleVisibility* tog2 = CCToggleVisibility::create(); tog1->autorelease(); tog2->autorelease(); CCFiniteTimeAction* seq = CCSequence::create( move1, tog1, move2, tog2, move1->reverse(), NULL);