From 33e32e987c3c70fe88c7e7d8a50f93ea64aea866 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 27 Jun 2012 18:44:25 +0800 Subject: [PATCH 1/2] Implement EffectsAdvancedTest (Effect4). --- .../EffectsAdvancedTest.cpp | 40 ++++++++++++++----- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/tests/tests/EffectsAdvancedTest/EffectsAdvancedTest.cpp b/tests/tests/EffectsAdvancedTest/EffectsAdvancedTest.cpp index b00ab2b3d9..8532c32ed5 100644 --- a/tests/tests/EffectsAdvancedTest/EffectsAdvancedTest.cpp +++ b/tests/tests/EffectsAdvancedTest/EffectsAdvancedTest.cpp @@ -123,22 +123,40 @@ std::string Effect3::title() // Effect4 // //------------------------------------------------------------------ + +class Lens3DTarget : public CCNode +{ +public: + virtual void setPosition(const CCPoint& var) + { + m_pLens3D->setPosition(var); + } + + static Lens3DTarget* create(CCLens3D* pAction) + { + Lens3DTarget* pRet = new Lens3DTarget(); + pRet->m_pLens3D = pAction; + pRet->autorelease(); + return pRet; + } +private: + CCLens3D* m_pLens3D; +}; + void Effect4::onEnter() { EffectAdvanceTextLayer::onEnter(); - CCActionInterval* lens = CCLens3D::create(ccp(100,180), 150, ccg(32,24), 10); - //id move = [MoveBy::create:5 position:ccp(400,0)]; + CCLens3D* lens = CCLens3D::create(ccp(100,180), 150, ccg(32,24), 10); + CCActionInterval* move = CCJumpBy::create(5, ccp(380,0), 100, 4); + CCActionInterval* move_back = move->reverse(); + CCActionInterval* seq = (CCActionInterval *)(CCSequence::create( move, move_back, NULL)); - /** - @todo we only support CCNode run actions now. - */ -// CCActionInterval* move = CCJumpBy::create(5, ccp(380,0), 100, 4); -// CCActionInterval* move_back = move->reverse(); -// CCActionInterval* seq = (CCActionInterval *)(CCSequence::create( move, move_back, NULL)); -// CCActionManager::sharedManager()->addAction(seq, lens, false); - - runAction( lens ); + CCDirector* director = CCDirector::sharedDirector(); + CCNode* pTarget = Lens3DTarget::create(lens); + director->getActionManager()->addAction(seq, pTarget, false); + addChild(pTarget); + this->runAction( lens ); } std::string Effect4::title() From 86942aedb4b50e0ec8663cec42a5d3c84ebf1889 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 27 Jun 2012 20:50:47 +0800 Subject: [PATCH 2/2] fixed #1368: Implement EffectsAdvancedTest (Effect4). Added some comments. --- .../EffectsAdvancedTest/EffectsAdvancedTest.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/tests/EffectsAdvancedTest/EffectsAdvancedTest.cpp b/tests/tests/EffectsAdvancedTest/EffectsAdvancedTest.cpp index 8532c32ed5..77971b6da1 100644 --- a/tests/tests/EffectsAdvancedTest/EffectsAdvancedTest.cpp +++ b/tests/tests/EffectsAdvancedTest/EffectsAdvancedTest.cpp @@ -140,6 +140,11 @@ public: return pRet; } private: + + Lens3DTarget() + : m_pLens3D(NULL) + {} + CCLens3D* m_pLens3D; }; @@ -152,10 +157,17 @@ void Effect4::onEnter() CCActionInterval* move_back = move->reverse(); CCActionInterval* seq = (CCActionInterval *)(CCSequence::create( move, move_back, NULL)); + /* In cocos2d-iphone, the type of action's target is 'id', so it supports using the instance of 'CCLens3D' as its target. + While in cocos2d-x, the target of action only supports CCNode or its subclass, + so we make an encapsulation for CCLens3D to achieve that. + */ + CCDirector* director = CCDirector::sharedDirector(); CCNode* pTarget = Lens3DTarget::create(lens); + // Please make sure the target been added to its parent. + this->addChild(pTarget); + director->getActionManager()->addAction(seq, pTarget, false); - addChild(pTarget); this->runAction( lens ); }