2010-09-09 16:15:21 +08:00
|
|
|
#include "SchedulerTest.h"
|
|
|
|
#include "../testResource.h"
|
|
|
|
|
|
|
|
enum {
|
2012-04-19 14:35:52 +08:00
|
|
|
kTagAnimationDance = 1,
|
2010-09-09 16:15:21 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int sceneIdx = -1;
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* nextSchedulerTest();
|
|
|
|
Layer* backSchedulerTest();
|
|
|
|
Layer* restartSchedulerTest();
|
2013-02-28 16:35:42 +08:00
|
|
|
|
|
|
|
TESTLAYER_CREATE_FUNC(SchedulerTimeScale)
|
|
|
|
TESTLAYER_CREATE_FUNC(TwoSchedulers)
|
|
|
|
TESTLAYER_CREATE_FUNC(SchedulerAutoremove)
|
|
|
|
TESTLAYER_CREATE_FUNC(SchedulerPauseResume)
|
|
|
|
TESTLAYER_CREATE_FUNC(SchedulerPauseResumeAll)
|
|
|
|
TESTLAYER_CREATE_FUNC(SchedulerPauseResumeAllUser)
|
|
|
|
TESTLAYER_CREATE_FUNC(SchedulerUnscheduleAll)
|
|
|
|
TESTLAYER_CREATE_FUNC(SchedulerUnscheduleAllHard)
|
|
|
|
TESTLAYER_CREATE_FUNC(SchedulerUnscheduleAllUserLevel)
|
|
|
|
TESTLAYER_CREATE_FUNC(SchedulerSchedulesAndRemove)
|
|
|
|
TESTLAYER_CREATE_FUNC(SchedulerUpdate)
|
|
|
|
TESTLAYER_CREATE_FUNC(SchedulerUpdateAndCustom)
|
|
|
|
TESTLAYER_CREATE_FUNC(SchedulerUpdateFromCustom)
|
|
|
|
TESTLAYER_CREATE_FUNC(RescheduleSelector)
|
|
|
|
TESTLAYER_CREATE_FUNC(SchedulerDelayAndRepeat)
|
2013-03-29 21:48:35 +08:00
|
|
|
TESTLAYER_CREATE_FUNC(SchedulerIssue2268)
|
2013-02-28 16:35:42 +08:00
|
|
|
|
|
|
|
static NEWTESTFUNC createFunctions[] = {
|
|
|
|
CF(SchedulerTimeScale),
|
|
|
|
CF(TwoSchedulers),
|
|
|
|
CF(SchedulerAutoremove),
|
|
|
|
CF(SchedulerPauseResume),
|
|
|
|
CF(SchedulerPauseResumeAll),
|
|
|
|
CF(SchedulerPauseResumeAllUser),
|
|
|
|
CF(SchedulerUnscheduleAll),
|
|
|
|
CF(SchedulerUnscheduleAllHard),
|
|
|
|
CF(SchedulerUnscheduleAllUserLevel),
|
|
|
|
CF(SchedulerSchedulesAndRemove),
|
|
|
|
CF(SchedulerUpdate),
|
|
|
|
CF(SchedulerUpdateAndCustom),
|
|
|
|
CF(SchedulerUpdateFromCustom),
|
|
|
|
CF(RescheduleSelector),
|
2013-03-29 21:48:35 +08:00
|
|
|
CF(SchedulerDelayAndRepeat),
|
|
|
|
CF(SchedulerIssue2268)
|
2012-12-03 15:33:01 +08:00
|
|
|
};
|
2011-07-08 15:57:46 +08:00
|
|
|
|
2012-12-03 15:33:01 +08:00
|
|
|
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))
|
2010-09-09 16:15:21 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* nextSchedulerTest()
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
sceneIdx++;
|
2012-12-03 15:33:01 +08:00
|
|
|
sceneIdx = sceneIdx % MAX_LAYER;
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = (createFunctions[sceneIdx])();
|
2013-07-23 08:25:44 +08:00
|
|
|
layer->init();
|
|
|
|
layer->autorelease();
|
2010-09-09 16:15:21 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
return layer;
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* backSchedulerTest()
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
sceneIdx--;
|
2012-12-03 15:33:01 +08:00
|
|
|
int total = MAX_LAYER;
|
2012-04-19 14:35:52 +08:00
|
|
|
if( sceneIdx < 0 )
|
2012-12-03 15:33:01 +08:00
|
|
|
sceneIdx += total;
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = (createFunctions[sceneIdx])();
|
2013-07-23 08:25:44 +08:00
|
|
|
layer->init();
|
|
|
|
layer->autorelease();
|
2010-09-09 16:15:21 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
return layer;
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* restartSchedulerTest()
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = (createFunctions[sceneIdx])();
|
2013-07-23 08:25:44 +08:00
|
|
|
layer->init();
|
|
|
|
layer->autorelease();
|
2012-12-03 15:33:01 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
return layer;
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SchedulerTestLayer
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void SchedulerTestLayer::onEnter()
|
|
|
|
{
|
2013-06-12 07:30:05 +08:00
|
|
|
BaseTest::onEnter();
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2013-07-26 06:53:24 +08:00
|
|
|
void SchedulerTestLayer::backCallback(Object* sender)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto scene = new SchedulerTestScene();
|
|
|
|
auto layer = backSchedulerTest();
|
2010-09-09 16:15:21 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
scene->addChild(layer);
|
|
|
|
Director::getInstance()->replaceScene(scene);
|
|
|
|
scene->release();
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2013-07-26 06:53:24 +08:00
|
|
|
void SchedulerTestLayer::nextCallback(Object* sender)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto scene = new SchedulerTestScene();
|
|
|
|
auto layer = nextSchedulerTest();
|
2010-09-09 16:15:21 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
scene->addChild(layer);
|
|
|
|
Director::getInstance()->replaceScene(scene);
|
|
|
|
scene->release();
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2013-07-26 06:53:24 +08:00
|
|
|
void SchedulerTestLayer::restartCallback(Object* sender)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto scene = new SchedulerTestScene();
|
|
|
|
auto layer = restartSchedulerTest();
|
2010-09-09 16:15:21 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
scene->addChild(layer);
|
|
|
|
Director::getInstance()->replaceScene(scene);
|
|
|
|
scene->release();
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerTestLayer::title()
|
|
|
|
{
|
|
|
|
return "No title";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerTestLayer::subtitle()
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SchedulerAutoremove
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void SchedulerAutoremove::onEnter()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onEnter();
|
|
|
|
|
|
|
|
schedule(schedule_selector(SchedulerAutoremove::autoremove), 0.5f);
|
|
|
|
schedule(schedule_selector(SchedulerAutoremove::tick), 0.5f);
|
|
|
|
accum = 0;
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void SchedulerAutoremove::autoremove(float dt)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
|
|
|
accum += dt;
|
2011-01-25 16:56:46 +08:00
|
|
|
CCLOG("Time: %f", accum);
|
2010-09-09 16:15:21 +08:00
|
|
|
|
|
|
|
if( accum > 3 )
|
|
|
|
{
|
|
|
|
unschedule(schedule_selector(SchedulerAutoremove::autoremove));
|
2011-01-25 16:56:46 +08:00
|
|
|
CCLOG("scheduler removed");
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void SchedulerAutoremove::tick(float dt)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2011-01-25 16:56:46 +08:00
|
|
|
CCLOG("This scheduler should not be removed");
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerAutoremove::title()
|
|
|
|
{
|
|
|
|
return "Self-remove an scheduler";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerAutoremove::subtitle()
|
|
|
|
{
|
|
|
|
return "1 scheduler will be autoremoved in 3 seconds. See console";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SchedulerPauseResume
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void SchedulerPauseResume::onEnter()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onEnter();
|
|
|
|
|
|
|
|
schedule(schedule_selector(SchedulerPauseResume::tick1), 0.5f);
|
|
|
|
schedule(schedule_selector(SchedulerPauseResume::tick2), 0.5f);
|
|
|
|
schedule(schedule_selector(SchedulerPauseResume::pause), 0.5f);
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void SchedulerPauseResume::tick1(float dt)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2011-01-25 16:56:46 +08:00
|
|
|
CCLOG("tick1");
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void SchedulerPauseResume::tick2(float dt)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2011-01-25 16:56:46 +08:00
|
|
|
CCLOG("tick2");
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void SchedulerPauseResume::pause(float dt)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->getScheduler()->pauseTarget(this);
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerPauseResume::title()
|
|
|
|
{
|
|
|
|
return "Pause / Resume";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerPauseResume::subtitle()
|
|
|
|
{
|
|
|
|
return "Scheduler should be paused after 3 seconds. See console";
|
|
|
|
}
|
|
|
|
|
2012-06-12 18:12:45 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SchedulerPauseResumeAll
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
SchedulerPauseResumeAll::SchedulerPauseResumeAll()
|
2013-06-15 14:03:30 +08:00
|
|
|
: _pausedTargets(NULL)
|
2012-06-12 18:12:45 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SchedulerPauseResumeAll::~SchedulerPauseResumeAll()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_RELEASE(_pausedTargets);
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SchedulerPauseResumeAll::onEnter()
|
|
|
|
{
|
2012-11-15 18:34:23 +08:00
|
|
|
SchedulerTestLayer::onEnter();
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto sprite = Sprite::create("Images/grossinis_sister1.png");
|
2012-11-15 18:34:23 +08:00
|
|
|
sprite->setPosition(VisibleRect::center());
|
|
|
|
this->addChild(sprite);
|
2013-06-20 14:17:10 +08:00
|
|
|
sprite->runAction(RepeatForever::create(RotateBy::create(3.0, 360)));
|
2012-06-12 18:12:45 +08:00
|
|
|
|
2012-11-20 16:24:27 +08:00
|
|
|
scheduleUpdate();
|
2012-06-12 18:12:45 +08:00
|
|
|
schedule(schedule_selector(SchedulerPauseResumeAll::tick1), 0.5f);
|
|
|
|
schedule(schedule_selector(SchedulerPauseResumeAll::tick2), 1.0f);
|
|
|
|
schedule(schedule_selector(SchedulerPauseResumeAll::pause), 3.0f, false, 0);
|
2012-11-20 16:24:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SchedulerPauseResumeAll::update(float delta)
|
|
|
|
{
|
|
|
|
// do nothing
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SchedulerPauseResumeAll::onExit()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if(_pausedTargets != NULL)
|
2012-11-15 18:34:23 +08:00
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->getScheduler()->resumeTargets(_pausedTargets);
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
2013-09-19 18:53:45 +08:00
|
|
|
SchedulerTestLayer::onExit();
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SchedulerPauseResumeAll::tick1(float dt)
|
|
|
|
{
|
2013-07-24 06:20:22 +08:00
|
|
|
log("tick1");
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SchedulerPauseResumeAll::tick2(float dt)
|
|
|
|
{
|
2013-07-24 06:20:22 +08:00
|
|
|
log("tick2");
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SchedulerPauseResumeAll::pause(float dt)
|
|
|
|
{
|
2013-07-24 06:20:22 +08:00
|
|
|
log("Pausing");
|
2013-08-16 16:05:27 +08:00
|
|
|
auto director = Director::getInstance();
|
2013-07-23 08:25:44 +08:00
|
|
|
_pausedTargets = director->getScheduler()->pauseAllTargets();
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_RETAIN(_pausedTargets);
|
2012-11-20 16:24:27 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
unsigned int c = _pausedTargets->count();
|
2012-11-20 16:24:27 +08:00
|
|
|
|
|
|
|
if (c > 2)
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
// should have only 2 items: ActionManager, self
|
2013-07-24 06:20:22 +08:00
|
|
|
log("Error: pausedTargets should have only 2 items, and not %u", (unsigned int)c);
|
2012-11-20 16:24:27 +08:00
|
|
|
}
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SchedulerPauseResumeAll::resume(float dt)
|
|
|
|
{
|
2013-07-24 06:20:22 +08:00
|
|
|
log("Resuming");
|
2013-08-16 16:05:27 +08:00
|
|
|
auto director = Director::getInstance();
|
2013-07-23 08:25:44 +08:00
|
|
|
director->getScheduler()->resumeTargets(_pausedTargets);
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_RELEASE_NULL(_pausedTargets);
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerPauseResumeAll::title()
|
|
|
|
{
|
|
|
|
return "Pause / Resume";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerPauseResumeAll::subtitle()
|
|
|
|
{
|
|
|
|
return "Everything will pause after 3s, then resume at 5s. See console";
|
|
|
|
}
|
2012-11-15 18:34:23 +08:00
|
|
|
|
2012-06-12 18:12:45 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SchedulerPauseResumeAllUser
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
SchedulerPauseResumeAllUser::SchedulerPauseResumeAllUser()
|
2013-06-15 14:03:30 +08:00
|
|
|
: _pausedTargets(NULL)
|
2012-06-12 18:12:45 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SchedulerPauseResumeAllUser::~SchedulerPauseResumeAllUser()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_RELEASE(_pausedTargets);
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SchedulerPauseResumeAllUser::onEnter()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onEnter();
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-11-15 18:34:23 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto sprite = Sprite::create("Images/grossinis_sister1.png");
|
2013-07-12 14:11:55 +08:00
|
|
|
sprite->setPosition(Point(s.width/2, s.height/2));
|
2012-11-15 18:34:23 +08:00
|
|
|
this->addChild(sprite);
|
2013-06-20 14:17:10 +08:00
|
|
|
sprite->runAction(RepeatForever::create(RotateBy::create(3.0, 360)));
|
2012-06-12 18:12:45 +08:00
|
|
|
|
|
|
|
schedule(schedule_selector(SchedulerPauseResumeAllUser::tick1), 0.5f);
|
|
|
|
schedule(schedule_selector(SchedulerPauseResumeAllUser::tick2), 1.0f);
|
|
|
|
schedule(schedule_selector(SchedulerPauseResumeAllUser::pause), 3.0f, false, 0);
|
|
|
|
//TODO: [self performSelector:@selector(resume) withObject:nil afterDelay:5];
|
|
|
|
}
|
|
|
|
|
|
|
|
void SchedulerPauseResumeAllUser::onExit()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if(_pausedTargets != NULL)
|
2012-11-15 18:34:23 +08:00
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->getScheduler()->resumeTargets(_pausedTargets);
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
2013-09-19 18:53:45 +08:00
|
|
|
SchedulerTestLayer::onExit();
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SchedulerPauseResumeAllUser::tick1(float dt)
|
|
|
|
{
|
2013-07-24 06:20:22 +08:00
|
|
|
log("tick1");
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SchedulerPauseResumeAllUser::tick2(float dt)
|
|
|
|
{
|
2013-07-24 06:20:22 +08:00
|
|
|
log("tick2");
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SchedulerPauseResumeAllUser::pause(float dt)
|
|
|
|
{
|
2013-07-24 06:20:22 +08:00
|
|
|
log("Pausing");
|
2013-08-16 16:05:27 +08:00
|
|
|
auto director = Director::getInstance();
|
2013-07-25 21:04:32 +08:00
|
|
|
_pausedTargets = director->getScheduler()->pauseAllTargetsWithMinPriority(Scheduler::PRIORITY_NON_SYSTEM_MIN);
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_RETAIN(_pausedTargets);
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SchedulerPauseResumeAllUser::resume(float dt)
|
|
|
|
{
|
2013-07-24 06:20:22 +08:00
|
|
|
log("Resuming");
|
2013-08-16 16:05:27 +08:00
|
|
|
auto director = Director::getInstance();
|
2013-07-23 08:25:44 +08:00
|
|
|
director->getScheduler()->resumeTargets(_pausedTargets);
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_RELEASE_NULL(_pausedTargets);
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerPauseResumeAllUser::title()
|
|
|
|
{
|
|
|
|
return "Pause / Resume";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerPauseResumeAllUser::subtitle()
|
|
|
|
{
|
|
|
|
return "Everything will pause after 3s, then resume at 5s. See console";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-09 16:15:21 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SchedulerUnscheduleAll
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void SchedulerUnscheduleAll::onEnter()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onEnter();
|
|
|
|
|
|
|
|
schedule(schedule_selector(SchedulerUnscheduleAll::tick1), 0.5f);
|
|
|
|
schedule(schedule_selector(SchedulerUnscheduleAll::tick2), 1.0f);
|
|
|
|
schedule(schedule_selector(SchedulerUnscheduleAll::tick3), 1.5f);
|
|
|
|
schedule(schedule_selector(SchedulerUnscheduleAll::tick4), 1.5f);
|
|
|
|
schedule(schedule_selector(SchedulerUnscheduleAll::unscheduleAll), 4);
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void SchedulerUnscheduleAll::tick1(float dt)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2011-01-25 16:56:46 +08:00
|
|
|
CCLOG("tick1");
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void SchedulerUnscheduleAll::tick2(float dt)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2011-01-25 16:56:46 +08:00
|
|
|
CCLOG("tick2");
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void SchedulerUnscheduleAll::tick3(float dt)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2011-01-25 16:56:46 +08:00
|
|
|
CCLOG("tick3");
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void SchedulerUnscheduleAll::tick4(float dt)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2011-01-25 16:56:46 +08:00
|
|
|
CCLOG("tick4");
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void SchedulerUnscheduleAll::unscheduleAll(float dt)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
|
|
|
unscheduleAllSelectors();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerUnscheduleAll::title()
|
|
|
|
{
|
|
|
|
return "Unschedule All selectors";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerUnscheduleAll::subtitle()
|
|
|
|
{
|
|
|
|
return "All scheduled selectors will be unscheduled in 4 seconds. See console";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SchedulerUnscheduleAllHard
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void SchedulerUnscheduleAllHard::onEnter()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onEnter();
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-11-15 18:34:23 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto sprite = Sprite::create("Images/grossinis_sister1.png");
|
2013-07-12 14:11:55 +08:00
|
|
|
sprite->setPosition(Point(s.width/2, s.height/2));
|
2012-11-15 18:34:23 +08:00
|
|
|
this->addChild(sprite);
|
2013-06-20 14:17:10 +08:00
|
|
|
sprite->runAction(RepeatForever::create(RotateBy::create(3.0, 360)));
|
2012-11-15 18:34:23 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_actionManagerActive = true;
|
2012-06-12 18:12:45 +08:00
|
|
|
|
2010-09-09 16:15:21 +08:00
|
|
|
schedule(schedule_selector(SchedulerUnscheduleAllHard::tick1), 0.5f);
|
|
|
|
schedule(schedule_selector(SchedulerUnscheduleAllHard::tick2), 1.0f);
|
|
|
|
schedule(schedule_selector(SchedulerUnscheduleAllHard::tick3), 1.5f);
|
|
|
|
schedule(schedule_selector(SchedulerUnscheduleAllHard::tick4), 1.5f);
|
|
|
|
schedule(schedule_selector(SchedulerUnscheduleAllHard::unscheduleAll), 4);
|
|
|
|
}
|
|
|
|
|
2012-06-12 18:12:45 +08:00
|
|
|
void SchedulerUnscheduleAllHard::onExit()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if(!_actionManagerActive) {
|
2012-11-15 18:34:23 +08:00
|
|
|
// Restore the director's action manager.
|
2013-08-16 16:05:27 +08:00
|
|
|
auto director = Director::getInstance();
|
2013-07-25 21:04:32 +08:00
|
|
|
director->getScheduler()->scheduleUpdateForTarget(director->getActionManager(), Scheduler::PRIORITY_SYSTEM, false);
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
2013-09-19 18:53:45 +08:00
|
|
|
|
|
|
|
SchedulerTestLayer::onExit();
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void SchedulerUnscheduleAllHard::tick1(float dt)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2011-01-25 16:56:46 +08:00
|
|
|
CCLOG("tick1");
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void SchedulerUnscheduleAllHard::tick2(float dt)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2011-01-25 16:56:46 +08:00
|
|
|
CCLOG("tick2");
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void SchedulerUnscheduleAllHard::tick3(float dt)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2011-01-25 16:56:46 +08:00
|
|
|
CCLOG("tick3");
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void SchedulerUnscheduleAllHard::tick4(float dt)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2011-01-25 16:56:46 +08:00
|
|
|
CCLOG("tick4");
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void SchedulerUnscheduleAllHard::unscheduleAll(float dt)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->getScheduler()->unscheduleAll();
|
2013-06-15 14:03:30 +08:00
|
|
|
_actionManagerActive = false;
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerUnscheduleAllHard::title()
|
|
|
|
{
|
2012-06-12 18:12:45 +08:00
|
|
|
return "Unschedule All selectors (HARD)";
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerUnscheduleAllHard::subtitle()
|
|
|
|
{
|
2012-06-12 18:12:45 +08:00
|
|
|
return "Unschedules all user selectors after 4s. Action will stop. See console";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SchedulerUnscheduleAllUserLevel
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void SchedulerUnscheduleAllUserLevel::onEnter()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onEnter();
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-11-15 18:34:23 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto sprite = Sprite::create("Images/grossinis_sister1.png");
|
2013-07-12 14:11:55 +08:00
|
|
|
sprite->setPosition(Point(s.width/2, s.height/2));
|
2012-11-15 18:34:23 +08:00
|
|
|
this->addChild(sprite);
|
2013-06-20 14:17:10 +08:00
|
|
|
sprite->runAction(RepeatForever::create(RotateBy::create(3.0, 360)));
|
2012-06-12 18:12:45 +08:00
|
|
|
|
|
|
|
schedule(schedule_selector(SchedulerUnscheduleAllUserLevel::tick1), 0.5f);
|
|
|
|
schedule(schedule_selector(SchedulerUnscheduleAllUserLevel::tick2), 1.0f);
|
|
|
|
schedule(schedule_selector(SchedulerUnscheduleAllUserLevel::tick3), 1.5f);
|
|
|
|
schedule(schedule_selector(SchedulerUnscheduleAllUserLevel::tick4), 1.5f);
|
|
|
|
schedule(schedule_selector(SchedulerUnscheduleAllUserLevel::unscheduleAll), 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SchedulerUnscheduleAllUserLevel::tick1(float dt)
|
|
|
|
{
|
|
|
|
CCLOG("tick1");
|
|
|
|
}
|
|
|
|
|
|
|
|
void SchedulerUnscheduleAllUserLevel::tick2(float dt)
|
|
|
|
{
|
|
|
|
CCLOG("tick2");
|
|
|
|
}
|
|
|
|
|
|
|
|
void SchedulerUnscheduleAllUserLevel::tick3(float dt)
|
|
|
|
{
|
|
|
|
CCLOG("tick3");
|
|
|
|
}
|
|
|
|
|
|
|
|
void SchedulerUnscheduleAllUserLevel::tick4(float dt)
|
|
|
|
{
|
|
|
|
CCLOG("tick4");
|
|
|
|
}
|
|
|
|
|
|
|
|
void SchedulerUnscheduleAllUserLevel::unscheduleAll(float dt)
|
|
|
|
{
|
2013-07-25 21:04:32 +08:00
|
|
|
Director::getInstance()->getScheduler()->unscheduleAllWithMinPriority(Scheduler::PRIORITY_NON_SYSTEM_MIN);
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerUnscheduleAllUserLevel::title()
|
|
|
|
{
|
|
|
|
return "Unschedule All user selectors";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerUnscheduleAllUserLevel::subtitle()
|
|
|
|
{
|
|
|
|
return "Unschedules all user selectors after 4s. Action should not stop. See console";
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SchedulerSchedulesAndRemove
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void SchedulerSchedulesAndRemove::onEnter()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onEnter();
|
|
|
|
|
|
|
|
schedule(schedule_selector(SchedulerSchedulesAndRemove::tick1), 0.5f);
|
|
|
|
schedule(schedule_selector(SchedulerSchedulesAndRemove::tick2), 1.0f);
|
|
|
|
schedule(schedule_selector(SchedulerSchedulesAndRemove::scheduleAndUnschedule), 4.0f);
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void SchedulerSchedulesAndRemove::tick1(float dt)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2011-01-25 16:56:46 +08:00
|
|
|
CCLOG("tick1");
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void SchedulerSchedulesAndRemove::tick2(float dt)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2011-01-25 16:56:46 +08:00
|
|
|
CCLOG("tick2");
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void SchedulerSchedulesAndRemove::tick3(float dt)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2011-01-25 16:56:46 +08:00
|
|
|
CCLOG("tick3");
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void SchedulerSchedulesAndRemove::tick4(float dt)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2011-01-25 16:56:46 +08:00
|
|
|
CCLOG("tick4");
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerSchedulesAndRemove::title()
|
|
|
|
{
|
|
|
|
return "Schedule from Schedule";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerSchedulesAndRemove::subtitle()
|
|
|
|
{
|
|
|
|
return "Will unschedule and schedule selectors in 4s. See console";
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void SchedulerSchedulesAndRemove::scheduleAndUnschedule(float dt)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
|
|
|
unschedule(schedule_selector(SchedulerSchedulesAndRemove::tick1));
|
|
|
|
unschedule(schedule_selector(SchedulerSchedulesAndRemove::tick2));
|
|
|
|
unschedule(schedule_selector(SchedulerSchedulesAndRemove::scheduleAndUnschedule));
|
|
|
|
|
|
|
|
schedule(schedule_selector(SchedulerSchedulesAndRemove::tick3), 1.0f);
|
|
|
|
schedule(schedule_selector(SchedulerSchedulesAndRemove::tick4), 1.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TestNode
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2013-06-20 14:17:10 +08:00
|
|
|
void TestNode::initWithString(String* pStr, int priority)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_pstring = pStr;
|
|
|
|
_pstring->retain();
|
2010-09-09 16:15:21 +08:00
|
|
|
scheduleUpdateWithPriority(priority);
|
|
|
|
}
|
|
|
|
|
|
|
|
TestNode::~TestNode()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_pstring->release();
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2012-12-03 15:33:01 +08:00
|
|
|
void TestNode::update(float dt)
|
|
|
|
{
|
2013-04-19 15:47:14 +08:00
|
|
|
CC_UNUSED_PARAM(dt);
|
2013-07-24 06:20:22 +08:00
|
|
|
log("%s", _pstring->getCString());
|
2012-12-03 15:33:01 +08:00
|
|
|
}
|
|
|
|
|
2010-09-09 16:15:21 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SchedulerUpdate
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void SchedulerUpdate::onEnter()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onEnter();
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto d = new TestNode();
|
|
|
|
auto pStr = new String("---");
|
2010-09-09 16:15:21 +08:00
|
|
|
d->initWithString(pStr, 50);
|
|
|
|
pStr->release();
|
|
|
|
addChild(d);
|
|
|
|
d->release();
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto b = new TestNode();
|
2013-06-20 14:17:10 +08:00
|
|
|
pStr = new String("3rd");
|
2010-09-09 16:15:21 +08:00
|
|
|
b->initWithString(pStr, 0);
|
|
|
|
pStr->release();
|
|
|
|
addChild(b);
|
|
|
|
b->release();
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto a = new TestNode();
|
2013-06-20 14:17:10 +08:00
|
|
|
pStr = new String("1st");
|
2010-09-09 16:15:21 +08:00
|
|
|
a->initWithString(pStr, -10);
|
|
|
|
pStr->release();
|
|
|
|
addChild(a);
|
|
|
|
a->release();
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto c = new TestNode();
|
2013-06-20 14:17:10 +08:00
|
|
|
pStr = new String("4th");
|
2010-09-09 16:15:21 +08:00
|
|
|
c->initWithString(pStr, 10);
|
|
|
|
pStr->release();
|
|
|
|
addChild(c);
|
|
|
|
c->release();
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto e = new TestNode();
|
2013-06-20 14:17:10 +08:00
|
|
|
pStr = new String("5th");
|
2010-09-09 16:15:21 +08:00
|
|
|
e->initWithString(pStr, 20);
|
|
|
|
pStr->release();
|
|
|
|
addChild(e);
|
|
|
|
e->release();
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto f = new TestNode();
|
2013-06-20 14:17:10 +08:00
|
|
|
pStr = new String("2nd");
|
2010-09-09 16:15:21 +08:00
|
|
|
f->initWithString(pStr, -5);
|
|
|
|
pStr->release();
|
|
|
|
addChild(f);
|
|
|
|
f->release();
|
|
|
|
|
|
|
|
schedule(schedule_selector(SchedulerUpdate::removeUpdates), 4.0f);
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void SchedulerUpdate::removeUpdates(float dt)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto children = getChildren();
|
2010-09-09 16:15:21 +08:00
|
|
|
|
2013-08-16 18:23:41 +08:00
|
|
|
for (auto c : *children)
|
|
|
|
{
|
2013-08-20 08:09:28 +08:00
|
|
|
auto obj = static_cast<Object*>(c);
|
|
|
|
auto node = static_cast<Node*>(obj);
|
2013-08-16 18:23:41 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
if (! node)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2013-07-23 08:25:44 +08:00
|
|
|
node->unscheduleAllSelectors();
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerUpdate::title()
|
|
|
|
{
|
|
|
|
return "Schedule update with priority";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerUpdate::subtitle()
|
|
|
|
{
|
|
|
|
return "3 scheduled updates. Priority should work. Stops in 4s. See console";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SchedulerUpdateAndCustom
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void SchedulerUpdateAndCustom::onEnter()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onEnter();
|
|
|
|
|
|
|
|
scheduleUpdate();
|
|
|
|
schedule(schedule_selector(SchedulerUpdateAndCustom::tick));
|
|
|
|
schedule(schedule_selector(SchedulerUpdateAndCustom::stopSelectors), 0.4f);
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void SchedulerUpdateAndCustom::update(float dt)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2011-01-25 16:56:46 +08:00
|
|
|
CCLOG("update called:%f", dt);
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void SchedulerUpdateAndCustom::tick(float dt)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2011-01-25 16:56:46 +08:00
|
|
|
CCLOG("custom selector called:%f",dt);
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void SchedulerUpdateAndCustom::stopSelectors(float dt)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
|
|
|
unscheduleAllSelectors();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerUpdateAndCustom::title()
|
|
|
|
{
|
|
|
|
return "Schedule Update + custom selector";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerUpdateAndCustom::subtitle()
|
|
|
|
{
|
|
|
|
return "Update + custom selector at the same time. Stops in 4s. See console";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SchedulerUpdateFromCustom
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void SchedulerUpdateFromCustom::onEnter()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onEnter();
|
|
|
|
|
|
|
|
schedule(schedule_selector(SchedulerUpdateFromCustom::schedUpdate), 2.0f);
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void SchedulerUpdateFromCustom::update(float dt)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2011-01-25 16:56:46 +08:00
|
|
|
CCLOG("update called:%f", dt);
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void SchedulerUpdateFromCustom::schedUpdate(float dt)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
|
|
|
unschedule(schedule_selector(SchedulerUpdateFromCustom::schedUpdate));
|
|
|
|
scheduleUpdate();
|
|
|
|
schedule(schedule_selector(SchedulerUpdateFromCustom::stopUpdate), 2.0f);
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void SchedulerUpdateFromCustom::stopUpdate(float dt)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
|
|
|
unscheduleUpdate();
|
|
|
|
unschedule(schedule_selector(SchedulerUpdateFromCustom::stopUpdate));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerUpdateFromCustom::title()
|
|
|
|
{
|
|
|
|
return "Schedule Update in 2 sec";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerUpdateFromCustom::subtitle()
|
|
|
|
{
|
|
|
|
return "Update schedules in 2 secs. Stops 2 sec later. See console";
|
|
|
|
}
|
|
|
|
|
2010-09-25 14:19:15 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// RescheduleSelector
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void RescheduleSelector::onEnter()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onEnter();
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_interval = 1.0f;
|
|
|
|
_ticks = 0;
|
|
|
|
schedule(schedule_selector(RescheduleSelector::schedUpdate), _interval);
|
2010-09-25 14:19:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string RescheduleSelector::title()
|
|
|
|
{
|
|
|
|
return "Reschedule Selector";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string RescheduleSelector::subtitle()
|
|
|
|
{
|
|
|
|
return "Interval is 1 second, then 2, then 3...";
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void RescheduleSelector::schedUpdate(float dt)
|
2010-09-25 14:19:15 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_ticks++;
|
2011-01-25 16:56:46 +08:00
|
|
|
|
2012-06-12 18:12:45 +08:00
|
|
|
CCLOG("schedUpdate: %.4f", dt);
|
2013-06-15 14:03:30 +08:00
|
|
|
if ( _ticks > 3 )
|
2011-01-25 16:56:46 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_interval += 1.0f;
|
|
|
|
schedule(schedule_selector(RescheduleSelector::schedUpdate), _interval);
|
|
|
|
_ticks = 0;
|
2010-09-25 14:19:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-18 13:58:24 +08:00
|
|
|
// SchedulerDelayAndRepeat
|
|
|
|
|
|
|
|
void SchedulerDelayAndRepeat::onEnter()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onEnter();
|
|
|
|
schedule(schedule_selector(SchedulerDelayAndRepeat::update), 0, 4 , 3.f);
|
|
|
|
CCLOG("update is scheduled should begin after 3 seconds");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerDelayAndRepeat::title()
|
|
|
|
{
|
|
|
|
return "Schedule with delay of 3 sec, repeat 4 times";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerDelayAndRepeat::subtitle()
|
|
|
|
{
|
|
|
|
return "After 5 x executed, method unscheduled. See console";
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void SchedulerDelayAndRepeat::update(float dt)
|
2012-04-18 13:58:24 +08:00
|
|
|
{
|
2013-07-24 06:20:22 +08:00
|
|
|
log("update called:%f", dt);
|
2012-04-18 13:58:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// SchedulerTimeScale
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
ControlSlider* SchedulerTimeScale::sliderCtl()
|
2012-04-18 13:58:24 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
ControlSlider * slider = ControlSlider::create("extensions/sliderTrack2.png","extensions/sliderProgress2.png" ,"extensions/sliderThumb.png");
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2013-07-26 14:37:26 +08:00
|
|
|
slider->addTargetWithActionForControlEvents(this, cccontrol_selector(SchedulerTimeScale::sliderAction), Control::EventType::VALUE_CHANGED);
|
2012-04-18 13:58:24 +08:00
|
|
|
|
|
|
|
slider->setMinimumValue(-3.0f);
|
|
|
|
slider->setMaximumValue(3.0f);
|
|
|
|
slider->setValue(1.0f);
|
|
|
|
|
|
|
|
return slider;
|
|
|
|
}
|
|
|
|
|
2013-07-26 15:22:45 +08:00
|
|
|
void SchedulerTimeScale::sliderAction(Object* sender, Control::EventType controlEvent)
|
2012-04-18 13:58:24 +08:00
|
|
|
{
|
2013-07-26 06:53:24 +08:00
|
|
|
ControlSlider* pSliderCtl = static_cast<ControlSlider*>(sender);
|
2012-06-08 13:55:28 +08:00
|
|
|
float scale;
|
2012-04-18 13:58:24 +08:00
|
|
|
scale = pSliderCtl->getValue();
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->getScheduler()->setTimeScale(scale);
|
2012-04-18 13:58:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SchedulerTimeScale::onEnter()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onEnter();
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-04-18 13:58:24 +08:00
|
|
|
|
|
|
|
// rotate and jump
|
2013-08-16 16:05:27 +08:00
|
|
|
auto jump1 = JumpBy::create(4, Point(-s.width+80,0), 100, 4);
|
|
|
|
auto jump2 = jump1->reverse();
|
|
|
|
auto rot1 = RotateBy::create(4, 360*2);
|
|
|
|
auto rot2 = rot1->reverse();
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto seq3_1 = Sequence::create(jump2, jump1, NULL);
|
|
|
|
auto seq3_2 = Sequence::create(rot1, rot2, NULL);
|
|
|
|
auto spawn = Spawn::create(seq3_1, seq3_2, NULL);
|
|
|
|
auto action = Repeat::create(spawn, 50);
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto action2 = action->clone();
|
|
|
|
auto action3 = action->clone();
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto grossini = Sprite::create("Images/grossini.png");
|
|
|
|
auto tamara = Sprite::create("Images/grossinis_sister1.png");
|
|
|
|
auto kathia = Sprite::create("Images/grossinis_sister2.png");
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2013-07-12 14:11:55 +08:00
|
|
|
grossini->setPosition(Point(40,80));
|
|
|
|
tamara->setPosition(Point(40,80));
|
|
|
|
kathia->setPosition(Point(40,80));
|
2012-04-18 13:58:24 +08:00
|
|
|
|
|
|
|
addChild(grossini);
|
|
|
|
addChild(tamara);
|
|
|
|
addChild(kathia);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
grossini->runAction(Speed::create(action, 0.5f));
|
|
|
|
tamara->runAction(Speed::create(action2, 1.5f));
|
|
|
|
kathia->runAction(Speed::create(action3, 1.0f));
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto emitter = ParticleFireworks::create();
|
2013-11-07 21:48:39 +08:00
|
|
|
emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_stars1) );
|
2012-04-18 13:58:24 +08:00
|
|
|
addChild(emitter);
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_sliderCtl = sliderCtl();
|
2013-07-12 14:11:55 +08:00
|
|
|
_sliderCtl->setPosition(Point(s.width / 2.0f, s.height / 3.0f));
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
addChild(_sliderCtl);
|
2012-04-18 13:58:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SchedulerTimeScale::onExit()
|
|
|
|
{
|
|
|
|
// restore scale
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->getScheduler()->setTimeScale(1);
|
2012-04-18 13:58:24 +08:00
|
|
|
SchedulerTestLayer::onExit();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerTimeScale::title()
|
|
|
|
{
|
|
|
|
return "Scheduler timeScale Test";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerTimeScale::subtitle()
|
|
|
|
{
|
|
|
|
return "Fast-forward and rewind using scheduler.timeScale";
|
|
|
|
}
|
|
|
|
|
|
|
|
//TwoSchedulers
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
ControlSlider *TwoSchedulers::sliderCtl()
|
2012-04-18 13:58:24 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
// auto frame = CGRectMake(12.0f, 12.0f, 120.0f, 7.0f);
|
2013-06-20 14:17:10 +08:00
|
|
|
ControlSlider *slider = ControlSlider::create("extensions/sliderTrack2.png","extensions/sliderProgress2.png" ,"extensions/sliderThumb.png");
|
2012-04-18 13:58:24 +08:00
|
|
|
//[[UISlider alloc] initWithFrame:frame];
|
2013-07-26 14:37:26 +08:00
|
|
|
slider->addTargetWithActionForControlEvents(this, cccontrol_selector(TwoSchedulers::sliderAction), Control::EventType::VALUE_CHANGED);
|
2012-04-18 13:58:24 +08:00
|
|
|
|
|
|
|
// in case the parent view draws with a custom color or gradient, use a transparent color
|
|
|
|
//slider.backgroundColor = [UIColor clearColor];
|
|
|
|
|
|
|
|
slider->setMinimumValue(0.0f);
|
|
|
|
slider->setMaximumValue(2.0f);
|
|
|
|
//slider.continuous = YES;
|
|
|
|
slider->setValue(1.0f);
|
|
|
|
|
|
|
|
return slider;
|
|
|
|
}
|
|
|
|
|
2013-07-26 14:37:26 +08:00
|
|
|
void TwoSchedulers::sliderAction(Object* sender, Control::EventType controlEvent)
|
2012-04-18 13:58:24 +08:00
|
|
|
{
|
2012-06-08 13:55:28 +08:00
|
|
|
float scale;
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2013-07-09 05:38:14 +08:00
|
|
|
ControlSlider *slider = static_cast<ControlSlider*>(sender);
|
2012-04-18 13:58:24 +08:00
|
|
|
scale = slider->getValue();
|
|
|
|
|
|
|
|
if( sender == sliderCtl1 )
|
|
|
|
sched1->setTimeScale(scale);
|
|
|
|
else
|
|
|
|
sched2->setTimeScale(scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TwoSchedulers::onEnter()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onEnter();
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-04-18 13:58:24 +08:00
|
|
|
|
|
|
|
// rotate and jump
|
2013-08-16 16:05:27 +08:00
|
|
|
auto jump1 = JumpBy::create(4, Point(0,0), 100, 4);
|
|
|
|
auto jump2 = jump1->reverse();
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto seq = Sequence::create(jump2, jump1, NULL);
|
|
|
|
auto action = RepeatForever::create(seq);
|
2012-04-18 13:58:24 +08:00
|
|
|
|
|
|
|
//
|
|
|
|
// Center
|
|
|
|
//
|
2013-08-16 16:05:27 +08:00
|
|
|
auto grossini = Sprite::create("Images/grossini.png");
|
2012-04-18 13:58:24 +08:00
|
|
|
addChild(grossini);
|
2013-07-12 14:11:55 +08:00
|
|
|
grossini->setPosition(Point(s.width/2,100));
|
2013-06-19 07:12:28 +08:00
|
|
|
grossini->runAction(action->clone());
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto defaultScheduler = Director::getInstance()->getScheduler();
|
2012-04-18 13:58:24 +08:00
|
|
|
|
|
|
|
//
|
|
|
|
// Left:
|
|
|
|
//
|
|
|
|
|
|
|
|
// Create a new scheduler, and link it to the main scheduler
|
2013-06-20 14:17:10 +08:00
|
|
|
sched1 = new Scheduler();
|
2012-04-18 13:58:24 +08:00
|
|
|
|
|
|
|
defaultScheduler->scheduleUpdateForTarget(sched1, 0, false);
|
|
|
|
|
|
|
|
// Create a new ActionManager, and link it to the new scheudler
|
2013-06-20 14:17:10 +08:00
|
|
|
actionManager1 = new ActionManager();
|
2012-04-18 13:58:24 +08:00
|
|
|
sched1->scheduleUpdateForTarget(actionManager1, 0, false);
|
|
|
|
|
|
|
|
for( unsigned int i=0; i < 10; i++ )
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto sprite = Sprite::create("Images/grossinis_sister1.png");
|
2012-04-18 13:58:24 +08:00
|
|
|
|
|
|
|
// IMPORTANT: Set the actionManager running any action
|
|
|
|
sprite->setActionManager(actionManager1);
|
|
|
|
|
|
|
|
addChild(sprite);
|
2013-07-12 14:11:55 +08:00
|
|
|
sprite->setPosition(Point(30+15*i,100));
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2013-06-19 07:12:28 +08:00
|
|
|
sprite->runAction(action->clone());
|
2012-04-18 13:58:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Right:
|
|
|
|
//
|
|
|
|
|
|
|
|
// Create a new scheduler, and link it to the main scheduler
|
2013-06-20 14:17:10 +08:00
|
|
|
sched2 = new Scheduler();;
|
2012-04-18 13:58:24 +08:00
|
|
|
defaultScheduler->scheduleUpdateForTarget(sched2, 0, false);
|
|
|
|
|
|
|
|
// Create a new ActionManager, and link it to the new scheudler
|
2013-06-20 14:17:10 +08:00
|
|
|
actionManager2 = new ActionManager();
|
2012-04-18 13:58:24 +08:00
|
|
|
sched2->scheduleUpdateForTarget(actionManager2, 0, false);
|
|
|
|
|
|
|
|
for( unsigned int i=0; i < 10; i++ ) {
|
2013-08-16 16:05:27 +08:00
|
|
|
auto sprite = Sprite::create("Images/grossinis_sister2.png");
|
2012-04-18 13:58:24 +08:00
|
|
|
|
|
|
|
// IMPORTANT: Set the actionManager running any action
|
|
|
|
sprite->setActionManager(actionManager2);
|
|
|
|
|
|
|
|
addChild(sprite);
|
2013-07-12 14:11:55 +08:00
|
|
|
sprite->setPosition(Point(s.width-30-15*i,100));
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2013-06-19 07:12:28 +08:00
|
|
|
sprite->runAction(action->clone());
|
2012-04-18 13:58:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
sliderCtl1 = sliderCtl();
|
|
|
|
addChild(sliderCtl1);
|
|
|
|
sliderCtl1->retain();
|
2013-07-12 14:11:55 +08:00
|
|
|
sliderCtl1->setPosition(Point(s.width / 4.0f, VisibleRect::top().y - 20));
|
2012-04-18 13:58:24 +08:00
|
|
|
|
|
|
|
sliderCtl2 = sliderCtl();
|
|
|
|
addChild(sliderCtl2);
|
|
|
|
sliderCtl2->retain();
|
2013-07-12 14:11:55 +08:00
|
|
|
sliderCtl2->setPosition(Point(s.width / 4.0f*3.0f, VisibleRect::top().y-20));
|
2012-04-18 13:58:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TwoSchedulers::~TwoSchedulers()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto defaultScheduler = Director::getInstance()->getScheduler();
|
2012-11-15 18:34:23 +08:00
|
|
|
defaultScheduler->unscheduleAllForTarget(sched1);
|
|
|
|
defaultScheduler->unscheduleAllForTarget(sched2);
|
2012-04-18 13:58:24 +08:00
|
|
|
|
|
|
|
sliderCtl1->release();
|
|
|
|
sliderCtl2->release();
|
|
|
|
|
|
|
|
sched1->release();
|
|
|
|
sched2->release();
|
|
|
|
|
|
|
|
actionManager1->release();
|
|
|
|
actionManager2->release();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TwoSchedulers::title()
|
|
|
|
{
|
|
|
|
return "Two custom schedulers";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TwoSchedulers::subtitle()
|
|
|
|
{
|
|
|
|
return "Three schedulers. 2 custom + 1 default. Two different time scales";
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
class TestNode2 : public Node
|
2013-03-29 21:48:35 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
~TestNode2() {
|
2013-07-24 06:20:22 +08:00
|
|
|
cocos2d::log("Delete TestNode (should not crash)");
|
2013-03-29 21:48:35 +08:00
|
|
|
this->unscheduleAllSelectors();
|
|
|
|
}
|
|
|
|
|
|
|
|
void update(float dt) {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void SchedulerIssue2268::onEnter()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onEnter();
|
|
|
|
|
|
|
|
testNode = new TestNode2();
|
|
|
|
testNode->init();
|
|
|
|
testNode->autorelease();
|
|
|
|
testNode->retain();
|
|
|
|
testNode->schedule(SEL_SCHEDULE(&TestNode::update));
|
|
|
|
this->addChild(testNode);
|
|
|
|
|
|
|
|
|
|
|
|
this->scheduleOnce(SEL_SCHEDULE(&SchedulerIssue2268::update), 0.25f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SchedulerIssue2268::update(float dt)
|
|
|
|
{
|
|
|
|
if ( testNode != NULL ) {
|
|
|
|
// do something with testNode
|
|
|
|
|
|
|
|
// at some point we are done, pause the nodes actions and schedulers
|
|
|
|
testNode->removeFromParentAndCleanup(false);
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2013-03-29 21:48:35 +08:00
|
|
|
// at some other point we are completely done with the node and want to clear it
|
|
|
|
testNode->release();
|
|
|
|
testNode->unscheduleAllSelectors();
|
|
|
|
testNode = NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SchedulerIssue2268::~SchedulerIssue2268()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerIssue2268::title()
|
|
|
|
{
|
|
|
|
return "Issue #2268";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerIssue2268::subtitle()
|
|
|
|
{
|
|
|
|
return "Should not crash";
|
|
|
|
}
|
2010-09-09 16:15:21 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SchedulerTestScene
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void SchedulerTestScene::runThisTest()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = nextSchedulerTest();
|
2013-07-23 08:25:44 +08:00
|
|
|
addChild(layer);
|
2010-09-09 16:15:21 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(this);
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|