2012-04-19 14:35:52 +08:00
|
|
|
#include "ActionManagerTest.h"
|
|
|
|
#include "../testResource.h"
|
|
|
|
#include "cocos2d.h"
|
|
|
|
|
2010-08-30 15:04:46 +08:00
|
|
|
enum
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
kTagNode,
|
|
|
|
kTagGrossini,
|
2010-08-30 15:04:46 +08:00
|
|
|
kTagSequence,
|
2012-04-19 14:35:52 +08:00
|
|
|
};
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* nextActionManagerAction();
|
|
|
|
Layer* backActionManagerAction();
|
|
|
|
Layer* restartActionManagerAction();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
static int sceneIdx = -1;
|
|
|
|
|
|
|
|
#define MAX_LAYER 5
|
2010-08-30 15:04:46 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* createActionManagerLayer(int nIndex)
|
2010-08-30 15:04:46 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
switch(nIndex)
|
|
|
|
{
|
|
|
|
case 0: return new CrashTest();
|
|
|
|
case 1: return new LogicTest();
|
|
|
|
case 2: return new PauseTest();
|
2010-08-30 15:04:46 +08:00
|
|
|
case 3: return new RemoveTest();
|
|
|
|
case 4: return new ResumeTest();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2010-08-30 15:04:46 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return NULL;
|
2010-08-30 15:04:46 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* nextActionManagerAction()
|
2010-08-30 15:04:46 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
sceneIdx++;
|
|
|
|
sceneIdx = sceneIdx % MAX_LAYER;
|
2010-08-30 15:04:46 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* pLayer = createActionManagerLayer(sceneIdx);
|
2012-04-19 14:35:52 +08:00
|
|
|
pLayer->autorelease();
|
2010-08-30 15:04:46 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return pLayer;
|
2010-08-30 15:04:46 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* backActionManagerAction()
|
2010-08-30 15:04:46 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
sceneIdx--;
|
|
|
|
int total = MAX_LAYER;
|
|
|
|
if( sceneIdx < 0 )
|
|
|
|
sceneIdx += total;
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* pLayer = createActionManagerLayer(sceneIdx);
|
2012-04-19 14:35:52 +08:00
|
|
|
pLayer->autorelease();
|
|
|
|
|
|
|
|
return pLayer;
|
2010-08-30 15:04:46 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* restartActionManagerAction()
|
2010-08-30 15:04:46 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* pLayer = createActionManagerLayer(sceneIdx);
|
2012-04-19 14:35:52 +08:00
|
|
|
pLayer->autorelease();
|
|
|
|
|
|
|
|
return pLayer;
|
|
|
|
}
|
2010-08-30 15:04:46 +08:00
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ActionManagerTest
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
ActionManagerTest::ActionManagerTest(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ActionManagerTest::~ActionManagerTest(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-08-30 15:04:46 +08:00
|
|
|
std::string ActionManagerTest::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "No title";
|
2010-08-30 15:04:46 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void ActionManagerTest::restartCallback(Object* pSender)
|
2010-08-30 15:04:46 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Scene* s = new ActionManagerTestScene();
|
2012-04-19 14:35:52 +08:00
|
|
|
s->addChild(restartActionManagerAction());
|
2010-08-30 15:04:46 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Director::sharedDirector()->replaceScene(s);
|
2010-09-13 09:40:47 +08:00
|
|
|
s->release();
|
2010-08-30 15:04:46 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void ActionManagerTest::nextCallback(Object* pSender)
|
2010-08-30 15:04:46 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Scene* s = new ActionManagerTestScene();
|
2012-04-19 14:35:52 +08:00
|
|
|
s->addChild( nextActionManagerAction() );
|
2013-06-20 14:17:10 +08:00
|
|
|
Director::sharedDirector()->replaceScene(s);
|
2010-09-13 09:40:47 +08:00
|
|
|
s->release();
|
2010-08-30 15:04:46 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void ActionManagerTest::backCallback(Object* pSender)
|
2010-08-30 15:04:46 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Scene* s = new ActionManagerTestScene();
|
2012-04-19 14:35:52 +08:00
|
|
|
s->addChild( backActionManagerAction() );
|
2013-06-20 14:17:10 +08:00
|
|
|
Director::sharedDirector()->replaceScene(s);
|
2010-09-13 09:40:47 +08:00
|
|
|
s->release();
|
2010-08-30 15:04:46 +08:00
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2010-08-30 15:04:46 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Test1
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2010-08-30 15:04:46 +08:00
|
|
|
void CrashTest::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ActionManagerTest::onEnter();
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Sprite* child = Sprite::create(s_pPathGrossini);
|
2012-10-23 17:48:50 +08:00
|
|
|
child->setPosition( VisibleRect::center() );
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(child, 1);
|
|
|
|
|
|
|
|
//Sum of all action's duration is 1.5 second.
|
2013-06-20 14:17:10 +08:00
|
|
|
child->runAction(RotateBy::create(1.5f, 90));
|
|
|
|
child->runAction(Sequence::create(
|
|
|
|
DelayTime::create(1.4f),
|
|
|
|
FadeOut::create(1.1f),
|
2012-04-19 14:35:52 +08:00
|
|
|
NULL)
|
|
|
|
);
|
|
|
|
|
|
|
|
//After 1.5 second, self will be removed.
|
2013-06-20 14:17:10 +08:00
|
|
|
runAction( Sequence::create(
|
|
|
|
DelayTime::create(1.4f),
|
|
|
|
CallFunc::create(this, callfunc_selector(CrashTest::removeThis)),
|
2012-04-19 14:35:52 +08:00
|
|
|
NULL)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2010-08-30 15:04:46 +08:00
|
|
|
void CrashTest::removeThis()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_parent->removeChild(this, true);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
nextCallback(this);
|
|
|
|
}
|
|
|
|
|
2010-08-30 15:04:46 +08:00
|
|
|
std::string CrashTest::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Test 1. Should not crash";
|
|
|
|
}
|
|
|
|
|
2010-08-30 15:04:46 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Test2
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void LogicTest::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ActionManagerTest::onEnter();
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Sprite* grossini = Sprite::create(s_pPathGrossini);
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(grossini, 0, 2);
|
2012-10-23 17:48:50 +08:00
|
|
|
grossini->setPosition(VisibleRect::center());
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
grossini->runAction( Sequence::create(
|
|
|
|
MoveBy::create(1, ccp(150,0)),
|
|
|
|
CallFuncN::create(this, callfuncN_selector(LogicTest::bugMe)),
|
2012-04-19 14:35:52 +08:00
|
|
|
NULL)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void LogicTest::bugMe(Node* node)
|
2010-08-30 15:04:46 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
node->stopAllActions(); //After this stop next action not working, if remove this stop everything is working
|
2013-06-20 14:17:10 +08:00
|
|
|
node->runAction(ScaleTo::create(2, 2));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2010-08-30 15:04:46 +08:00
|
|
|
std::string LogicTest::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Logic test";
|
|
|
|
}
|
|
|
|
|
2010-08-30 15:04:46 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// PauseTest
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
void PauseTest::onEnter()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// This test MUST be done in 'onEnter' and not on 'init'
|
|
|
|
// otherwise the paused action will be resumed at 'onEnter' time
|
|
|
|
//
|
|
|
|
ActionManagerTest::onEnter();
|
|
|
|
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
LabelTTF* l = LabelTTF::create("After 5 seconds grossini should move", "Thonburi", 16);
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(l);
|
2012-10-23 17:48:50 +08:00
|
|
|
l->setPosition( ccp(VisibleRect::center().x, VisibleRect::top().y-75) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Also, this test MUST be done, after [super onEnter]
|
|
|
|
//
|
2013-06-20 14:17:10 +08:00
|
|
|
Sprite* grossini = Sprite::create(s_pPathGrossini);
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(grossini, 0, kTagGrossini);
|
2012-10-23 17:48:50 +08:00
|
|
|
grossini->setPosition(VisibleRect::center() );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Action* action = MoveBy::create(1, ccp(150,0));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Director* pDirector = Director::sharedDirector();
|
2012-04-19 14:35:52 +08:00
|
|
|
pDirector->getActionManager()->addAction(action, grossini, true);
|
|
|
|
|
|
|
|
schedule( schedule_selector(PauseTest::unpause), 3);
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void PauseTest::unpause(float dt)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
unschedule( schedule_selector(PauseTest::unpause) );
|
2013-06-20 14:17:10 +08:00
|
|
|
Node* node = getChildByTag( kTagGrossini );
|
|
|
|
Director* pDirector = Director::sharedDirector();
|
2012-04-19 14:35:52 +08:00
|
|
|
pDirector->getActionManager()->resumeTarget(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string PauseTest::title()
|
|
|
|
{
|
|
|
|
return "Pause Test";
|
|
|
|
}
|
|
|
|
|
2010-08-30 15:04:46 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// RemoveTest
|
|
|
|
//
|
2012-04-19 14:35:52 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
void RemoveTest::onEnter()
|
|
|
|
{
|
|
|
|
ActionManagerTest::onEnter();
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
LabelTTF* l = LabelTTF::create("Should not crash", "Thonburi", 16);
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(l);
|
2012-10-23 17:48:50 +08:00
|
|
|
l->setPosition( ccp(VisibleRect::center().x, VisibleRect::top().y - 75) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
MoveBy* pMove = MoveBy::create(2, ccp(200, 0));
|
|
|
|
CallFunc* pCallback = CallFunc::create(this, callfunc_selector(RemoveTest::stopAction));
|
|
|
|
ActionInterval* pSequence = Sequence::create(pMove, pCallback, NULL);
|
2012-04-19 14:35:52 +08:00
|
|
|
pSequence->setTag(kTagSequence);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Sprite* pChild = Sprite::create(s_pPathGrossini);
|
2012-10-23 17:48:50 +08:00
|
|
|
pChild->setPosition( VisibleRect::center() );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
addChild(pChild, 1, kTagGrossini);
|
|
|
|
pChild->runAction(pSequence);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveTest::stopAction()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Node* pSprite = getChildByTag(kTagGrossini);
|
2012-04-19 14:35:52 +08:00
|
|
|
pSprite->stopActionByTag(kTagSequence);
|
|
|
|
}
|
|
|
|
|
2010-08-30 15:04:46 +08:00
|
|
|
std::string RemoveTest::title()
|
|
|
|
{
|
|
|
|
return "Remove Test";
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2010-08-30 15:04:46 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ResumeTest
|
|
|
|
//
|
2012-04-19 14:35:52 +08:00
|
|
|
//------------------------------------------------------------------
|
2010-08-30 15:04:46 +08:00
|
|
|
std::string ResumeTest::title()
|
|
|
|
{
|
|
|
|
return "Resume Test";
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResumeTest::onEnter()
|
|
|
|
{
|
2010-09-02 15:15:45 +08:00
|
|
|
ActionManagerTest::onEnter();
|
2010-08-30 15:04:46 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
LabelTTF* l = LabelTTF::create("Grossini only rotate/scale in 3 seconds", "Thonburi", 16);
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(l);
|
2012-10-23 17:48:50 +08:00
|
|
|
l->setPosition( ccp(VisibleRect::center().x, VisibleRect::top().y - 75));
|
2010-08-30 15:04:46 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Sprite* pGrossini = Sprite::create(s_pPathGrossini);
|
2010-08-30 15:04:46 +08:00
|
|
|
addChild(pGrossini, 0, kTagGrossini);
|
2012-10-23 17:48:50 +08:00
|
|
|
pGrossini->setPosition(VisibleRect::center());
|
2010-08-30 15:04:46 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
pGrossini->runAction(ScaleBy::create(2, 2));
|
2010-08-30 15:04:46 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Director* pDirector = Director::sharedDirector();
|
2012-04-19 14:35:52 +08:00
|
|
|
pDirector->getActionManager()->pauseTarget(pGrossini);
|
2013-06-20 14:17:10 +08:00
|
|
|
pGrossini->runAction(RotateBy::create(2, 360));
|
2010-08-30 15:04:46 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
this->schedule(schedule_selector(ResumeTest::resumeGrossini), 3.0f);
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void ResumeTest::resumeGrossini(float time)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
this->unschedule(schedule_selector(ResumeTest::resumeGrossini));
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Node* pGrossini = getChildByTag(kTagGrossini);
|
|
|
|
Director* pDirector = Director::sharedDirector();
|
2012-04-19 14:35:52 +08:00
|
|
|
pDirector->getActionManager()->resumeTarget(pGrossini);
|
2010-08-30 15:04:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ActionManagerTestScene
|
|
|
|
//
|
2012-04-19 14:35:52 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ActionManagerTestScene::runThisTest()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* pLayer = nextActionManagerAction();
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(pLayer);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Director::sharedDirector()->replaceScene(this);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|