code:
#include "PerformanceTextureTest.h"

enum
{
    TEST_COUNT = 1,
};

static int s_nTexCurCase = 0;

float calculateDeltaTime( struct timeval *lastUpdate )
{
    struct timeval now;

    gettimeofday( &now, NULL);

    float dt = (now.tv_sec - lastUpdate->tv_sec) + (now.tv_usec - lastUpdate->tv_usec) / 1000000.0f;

    return dt;
}

////////////////////////////////////////////////////////
//
// TextureMenuLayer
//
////////////////////////////////////////////////////////
void TextureMenuLayer::showCurrentTest()
{
    CCScene* pScene = NULL;

    switch (m_nCurCase)
    {
    case 0:
        pScene = TextureTest::scene();
        break;
    }
    s_nTexCurCase = m_nCurCase;

    if (pScene)
    {
        CCDirector::sharedDirector()->replaceScene(pScene);
    }
}

void TextureMenuLayer::onEnter()
{
    PerformBasicLayer::onEnter();

    CCSize s = CCDirector::sharedDirector()->getWinSize();

    // Title
    CCLabelTTF *label = CCLabelTTF::labelWithString(title().c_str(), "Arial", 40);
    addChild(label, 1);
    label->setPosition(ccp(s.width/2, s.height-32));
    label->setColor(ccc3(255,255,40));

    // Subtitle
    std::string strSubTitle = subtitle();
    if(strSubTitle.length())
    {
        CCLabelTTF *l = CCLabelTTF::labelWithString(strSubTitle.c_str(), "Thonburi", 16);
        addChild(l, 1);
        l->setPosition(ccp(s.width/2, s.height-80));
    }

    performTests();
}

std::string TextureMenuLayer::title()
{
    return "no title";
}

std::string TextureMenuLayer::subtitle()
{
    return "no subtitle";
}

////////////////////////////////////////////////////////
//
// TextureTest
//
////////////////////////////////////////////////////////
void TextureTest::performTestsPNG(const char* filename)
{
    struct timeval now;
    CCTexture2D *texture;
    CCTextureCache *cache = CCTextureCache::sharedTextureCache();

    CCLog("RGBA 8888");
    CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA8888);
    gettimeofday(&now, NULL);
    texture = cache->addImage(filename);
    if( texture )
        CCLog("  ms:%f\n", calculateDeltaTime(&now) );
    else
        CCLog(" ERROR\n");
    cache->removeTexture(texture);

    CCLog("RGBA 4444");
    CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA4444);
    gettimeofday(&now, NULL);
    texture = cache->addImage(filename);
    if( texture )
        CCLog("  ms:%f\n", calculateDeltaTime(&now) );
    else
        CCLog(" ERROR\n");
    cache->removeTexture(texture);

    CCLog("RGBA 5551");
    CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGB5A1);
    gettimeofday(&now, NULL);
    texture = cache->addImage(filename);
    if( texture )
        CCLog("  ms:%f\n", calculateDeltaTime(&now) );
    else
        CCLog(" ERROR\n");
    cache->removeTexture(texture);

    CCLog("RGB 565");
    CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGB565);
    gettimeofday(&now, NULL);
    texture = cache->addImage(filename);
    if( texture )
        CCLog("  ms:%f\n", calculateDeltaTime(&now) );
    else
        CCLog(" ERROR\n");
    cache->removeTexture(texture);
}

void TextureTest::performTests()
{
//     CCTexture2D *texture;
//     struct timeval now;
//     CCTextureCache *cache = CCTextureCache::sharedTextureCache();

    CCLog("\n\n--------\n\n");

    CCLog("--- PNG 128x128 ---\n");
    performTestsPNG("Images/test_image.png");

//     CCLog("--- PVR 128x128 ---\n");
//     CCLog("RGBA 8888");
//     gettimeofday(&now, NULL);
//     texture = cache->addImage("Images/test_image_rgba8888.pvr");
//     if( texture )
//         CCLog("  ms:%f\n", calculateDeltaTime(&now) );
//     else
//         CCLog("ERROR\n");
//     cache->removeTexture(texture);
//
//     CCLog("BGRA 8888");
//     gettimeofday(&now, NULL);
//     texture = cache->addImage("Images/test_image_bgra8888.pvr");
//     if( texture )
//         CCLog("  ms:%f\n", calculateDeltaTime(&now) );
//     else
//         CCLog("ERROR\n");
//     cache->removeTexture(texture);
//
//     CCLog("RGBA 4444");
//     gettimeofday(&now, NULL);
//     texture = cache->addImage("Images/test_image_rgba4444.pvr");
//     if( texture )
//         CCLog("  ms:%f\n", calculateDeltaTime(&now) );
//     else
//         CCLog("ERROR\n");
//     cache->removeTexture(texture);
//
//     CCLog("RGB 565");
//     gettimeofday(&now, NULL);
//     texture = cache->addImage("Images/test_image_rgb565.pvr");
//     if( texture )
//         CCLog("  ms:%f\n", calculateDeltaTime(&now) );
//     else
//         CCLog("ERROR\n");
//     cache->removeTexture(texture);

    CCLog("\n\n--- PNG 512x512 ---\n");
    performTestsPNG("Images/texture512x512.png");

//     CCLog("--- PVR 512x512 ---\n");
//     CCLog("RGBA 4444");
//     gettimeofday(&now, NULL);
//     texture = cache->addImage("Images/texture512x512_rgba4444.pvr");
//     if( texture )
//         CCLog("  ms:%f\n", calculateDeltaTime(&now) );
//     else
//         CCLog("ERROR\n");
//     cache->removeTexture(texture);

    //
    // ---- 1024X1024
    // RGBA4444
    // Empty image
    //

    CCLog("\n\nEMPTY IMAGE\n\n");
    CCLog("--- PNG 1024x1024 ---\n");
    performTestsPNG("Images/texture1024x1024.png");

//     CCLog("--- PVR 1024x1024 ---\n");
//     CCLog("RGBA 4444");
//     gettimeofday(&now, NULL);
//     texture = cache->addImage("Images/texture1024x1024_rgba4444.pvr");
//     if( texture )
//         CCLog("  ms:%f\n", calculateDeltaTime(&now) );
//     else
//         CCLog("ERROR\n");
//     cache->removeTexture(texture);
//
//     CCLog("--- PVR.GZ 1024x1024 ---\n");
//     CCLog("RGBA 4444");
//     gettimeofday(&now, NULL);
//     texture = cache->addImage("Images/texture1024x1024_rgba4444.pvr.gz");
//     if( texture )
//         CCLog("  ms:%f\n", calculateDeltaTime(&now) );
//     else
//         CCLog("ERROR\n");
//     cache->removeTexture(texture);
//
//     CCLog("--- PVR.CCZ 1024x1024 ---\n");
//     CCLog("RGBA 4444");
//     gettimeofday(&now, NULL);
//     texture = cache->addImage("Images/texture1024x1024_rgba4444.pvr.ccz");
//     if( texture )
//         CCLog("  ms:%f\n", calculateDeltaTime(&now) );
//     else
//         CCLog("ERROR\n");
//     cache->removeTexture(texture);

    //
    // ---- 1024X1024
    // RGBA4444
    // SpriteSheet images
    //

    CCLog("\n\nSPRITESHEET IMAGE\n\n");
    CCLog("--- PNG 1024x1024 ---\n");
    performTestsPNG("Images/PlanetCute-1024x1024.png");

//     CCLog("--- PVR 1024x1024 ---\n");
//     CCLog("RGBA 4444");
//     gettimeofday(&now, NULL);
//     texture = cache->addImage("Images/PlanetCute-1024x1024-rgba4444.pvr");
//     if( texture )
//         CCLog("  ms:%f\n", calculateDeltaTime(&now) );
//     else
//         CCLog("ERROR\n");
//     cache->removeTexture(texture);
//
//     CCLog("--- PVR.GZ 1024x1024 ---\n");
//     CCLog("RGBA 4444");
//     gettimeofday(&now, NULL);
//     texture = cache->addImage("Images/PlanetCute-1024x1024-rgba4444.pvr.gz");
//     if( texture )
//         CCLog("  ms:%f\n", calculateDeltaTime(&now) );
//     else
//         CCLog("ERROR\n");
//     cache->removeTexture(texture);
//
//     CCLog("--- PVR.CCZ 1024x1024 ---\n");
//     CCLog("RGBA 4444");
//     gettimeofday(&now, NULL);
//     texture = cache->addImage("Images/PlanetCute-1024x1024-rgba4444.pvr.ccz");
//     if( texture )
//         CCLog("  ms:%f\n", calculateDeltaTime(&now) );
//     else
//         CCLog("ERROR\n");
//     cache->removeTexture(texture);

    //
    // ---- 1024X1024
    // RGBA8888
    // Landscape Image
    //

    CCLog("\n\nLANDSCAPE IMAGE\n\n");

    CCLog("--- PNG 1024x1024 ---\n");
    performTestsPNG("Images/landscape-1024x1024.png");

//     CCLog("--- PVR 1024x1024 ---\n");
//     CCLog("RGBA 8888");
//     gettimeofday(&now, NULL);
//     texture = cache->addImage("Images/landscape-1024x1024-rgba8888.pvr");
//     if( texture )
//         CCLog("  ms:%f\n", calculateDeltaTime(&now) );
//     else
//         CCLog("ERROR\n");
//     cache->removeTexture(texture);
//
//     CCLog("--- PVR.GZ 1024x1024 ---\n");
//     CCLog("RGBA 8888");
//     gettimeofday(&now, NULL);
//     texture = cache->addImage("Images/landscape-1024x1024-rgba8888.pvr.gz");
//     if( texture )
//         CCLog("  ms:%f\n", calculateDeltaTime(&now) );
//     else
//         CCLog("ERROR\n");
//     cache->removeTexture(texture);
//
//     CCLog("--- PVR.CCZ 1024x1024 ---\n");
//     CCLog("RGBA 8888");
//     gettimeofday(&now, NULL);
//     texture = cache->addImage("Images/landscape-1024x1024-rgba8888.pvr.ccz");
//     if( texture )
//         CCLog("  ms:%f\n", calculateDeltaTime(&now) );
//     else
//         CCLog("ERROR\n");
//     cache->removeTexture(texture);

    //
    // 2048x2048
    // RGBA444
    //

// most platform don't support texture with width/height is 2048
//     CCLog("\n\n--- PNG 2048x2048 ---\n");
//     performTestsPNG("Images/texture2048x2048.png");

//     CCLog("--- PVR 2048x2048 ---\n");
//     CCLog("RGBA 4444");
//     gettimeofday(&now, NULL);
//     texture = cache->addImage("Images/texture2048x2048_rgba4444.pvr");
//     if( texture )
//         CCLog("  ms:%f\n", calculateDeltaTime(&now) );
//     else
//         CCLog("ERROR\n");
//     cache->removeTexture(texture);
}

std::string TextureTest::title()
{
    return "Texture Performance Test";
}

std::string TextureTest::subtitle()
{
    return "See console for results";
}

CCScene* TextureTest::scene()
{
    CCScene *pScene = CCScene::node();
    TextureTest *layer = new TextureTest(false, TEST_COUNT, s_nTexCurCase);
    pScene->addChild(layer);
    layer->release();

    return pScene;
}

void runTextureTest()
{
    s_nTexCurCase = 0;
    CCScene* pScene = TextureTest::scene();
    CCDirector::sharedDirector()->replaceScene(pScene);
}


code:
#ifndef __PERFORMANCE_TEXTURE_TEST_H__
#define __PERFORMANCE_TEXTURE_TEST_H__

#include "PerformanceTest.h"

class TextureMenuLayer : public PerformBasicLayer
{
public:
    TextureMenuLayer(bool bControlMenuVisible, int nMaxCases = 0, int nCurCase = 0)
        :PerformBasicLayer(bControlMenuVisible, nMaxCases, nCurCase)
    {
    }

    virtual void showCurrentTest();

    virtual void onEnter();
    virtual std::string title();
    virtual std::string subtitle();
    virtual void performTests() = 0;
};

class TextureTest : public TextureMenuLayer
{
public:
    TextureTest(bool bControlMenuVisible, int nMaxCases = 0, int nCurCase = 0)
        :TextureMenuLayer(bControlMenuVisible, nMaxCases, nCurCase)
    {
    }

    virtual void performTests();
    virtual std::string title();
    virtual std::string subtitle();
    void performTestsPNG(const char* filename);

    static CCScene* scene();
};

void runTextureTest();

#endif

license: mit


code:
#include "PerformanceTouchesTest.h"

enum
{
    TEST_COUNT = 2,
};

static int s_nTouchCurCase = 0;

////////////////////////////////////////////////////////
//
// TouchesMainScene
//
////////////////////////////////////////////////////////
void TouchesMainScene::showCurrentTest()
{
    CCLayer* pLayer = NULL;
    switch (m_nCurCase)
    {
    case 0:
        pLayer = new TouchesPerformTest1(true, TEST_COUNT, m_nCurCase);
        break;
    case 1:
        pLayer = new TouchesPerformTest2(true, TEST_COUNT, m_nCurCase);
        break;
    }
    s_nTouchCurCase = m_nCurCase;

    if (pLayer)
    {
        CCScene* pScene = CCScene::node();
        pScene->addChild(pLayer);
        pLayer->release();

        CCDirector::sharedDirector()->replaceScene(pScene);
    }
}

void TouchesMainScene::onEnter()
{
    PerformBasicLayer::onEnter();

    CCSize s = CCDirector::sharedDirector()->getWinSize();

    // add title
    CCLabelTTF *label = CCLabelTTF::labelWithString(title().c_str(), "Arial", 32);
    addChild(label, 1);
    label->setPosition(ccp(s.width/2, s.height-50));

    scheduleUpdate();

    m_plabel = CCLabelBMFont::labelWithString("00.0", "fonts/arial16.fnt");
    m_plabel->setPosition(ccp(s.width/2, s.height/2));
    addChild(m_plabel);

    elapsedTime = 0;
    numberOfTouchesB = numberOfTouchesM = numberOfTouchesE = numberOfTouchesC = 0;
}

void TouchesMainScene::update(ccTime dt)
{
    elapsedTime += dt;

    if ( elapsedTime > 1.0f)
    {
        float frameRateB = numberOfTouchesB / elapsedTime;
        float frameRateM = numberOfTouchesM / elapsedTime;
        float frameRateE = numberOfTouchesE / elapsedTime;
        float frameRateC = numberOfTouchesC / elapsedTime;
        elapsedTime = 0;
        numberOfTouchesB = numberOfTouchesM = numberOfTouchesE = numberOfTouchesC = 0;

        char str[32] = {0};
        sprintf(str, "%.1f %.1f %.1f %.1f", frameRateB, frameRateM, frameRateE, frameRateC);
        m_plabel->setString(str);
    }
}

std::string TouchesMainScene::title()
{
    return "No title";
}

////////////////////////////////////////////////////////
//
// TouchesPerformTest1
//
////////////////////////////////////////////////////////
void TouchesPerformTest1::onEnter()
{
    TouchesMainScene::onEnter();
    setIsTouchEnabled(true);
}

std::string TouchesPerformTest1::title()
{
    return "Targeted touches";
}

void TouchesPerformTest1::registerWithTouchDispatcher()
{
    CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, 0, true);
}

bool TouchesPerformTest1::ccTouchBegan(CCTouch* touch, CCEvent* event)
{
    numberOfTouchesB++;
    return true;
}

void TouchesPerformTest1::ccTouchMoved(CCTouch* touch, CCEvent* event)
{
    numberOfTouchesM++;
}

void TouchesPerformTest1::ccTouchEnded(CCTouch* touch, CCEvent* event)
{
    numberOfTouchesE++;
}

void TouchesPerformTest1::ccTouchCancelled(CCTouch* touch, CCEvent* event)
{
    numberOfTouchesC++;
}

////////////////////////////////////////////////////////
//
// TouchesPerformTest2
//
////////////////////////////////////////////////////////
void TouchesPerformTest2::onEnter()
{
    TouchesMainScene::onEnter();
    setIsTouchEnabled(true);
}

std::string TouchesPerformTest2::title()
{
    return "Standard touches";
}

void TouchesPerformTest2::registerWithTouchDispatcher()
{
    CCTouchDispatcher::sharedDispatcher()->addStandardDelegate(this, 0);
}

void TouchesPerformTest2::ccTouchesBegan(CCSet* touches, CCEvent* event)
{
    numberOfTouchesB += touches->count();
}

void TouchesPerformTest2::ccTouchesMoved(CCSet* touches, CCEvent* event)
{
    numberOfTouchesM += touches->count();
}
void TouchesPerformTest2::ccTouchesEnded(CCSet* touches, CCEvent* event)
{
    numberOfTouchesE += touches->count();
}

void TouchesPerformTest2::ccTouchesCancelled(CCSet* touches, CCEvent* event)
{
    numberOfTouchesC += touches->count();
}

void runTouchesTest()
{
    s_nTouchCurCase = 0;
    CCScene* pScene = CCScene::node();
    CCLayer* pLayer = new TouchesPerformTest1(true, TEST_COUNT, s_nTouchCurCase);

    pScene->addChild(pLayer);
    pLayer->release();

    CCDirector::sharedDirector()->replaceScene(pScene);
}


code:
#ifndef __PERFORMANCE_TOUCHES_TEST_H__
#define __PERFORMANCE_TOUCHES_TEST_H__

#include "PerformanceTest.h"

class TouchesMainScene : public PerformBasicLayer
{
public:
    TouchesMainScene(bool bControlMenuVisible, int nMaxCases = 0, int nCurCase = 0)
        : PerformBasicLayer(bControlMenuVisible, nMaxCases, nCurCase)
    {
    }

    virtual void showCurrentTest();
    virtual void onEnter();
    virtual std::string title();
    virtual void update(ccTime dt);

protected:
    CCLabelBMFont * m_plabel;
    int				numberOfTouchesB;
    int				numberOfTouchesM;
    int				numberOfTouchesE;
    int				numberOfTouchesC;
    ccTime			elapsedTime;
};

class TouchesPerformTest1 : public TouchesMainScene
{
public:
    TouchesPerformTest1(bool bControlMenuVisible, int nMaxCases = 0, int nCurCase = 0)
        : TouchesMainScene(bControlMenuVisible, nMaxCases, nCurCase)
    {
    }

    virtual void onEnter();
    virtual std::string title();
    virtual void registerWithTouchDispatcher();

    virtual bool ccTouchBegan(CCTouch* touch, CCEvent* event);
    virtual void ccTouchMoved(CCTouch* touch, CCEvent* event);
    virtual void ccTouchEnded(CCTouch* touch, CCEvent* event);
    virtual void ccTouchCancelled(CCTouch* touch, CCEvent* event);
};

class TouchesPerformTest2 : public TouchesMainScene
{
public:
    TouchesPerformTest2(bool bControlMenuVisible, int nMaxCases = 0, int nCurCase = 0)
        : TouchesMainScene(bControlMenuVisible, nMaxCases, nCurCase)
    {
    }

    virtual void onEnter();
    virtual std::string title();
    virtual void registerWithTouchDispatcher();

    virtual void ccTouchesBegan(CCSet* touches, CCEvent* event);
    virtual void ccTouchesMoved(CCSet* touches, CCEvent* event);
    virtual void ccTouchesEnded(CCSet* touches, CCEvent* event);
    virtual void ccTouchesCancelled(CCSet* touches, CCEvent* event);
};

void runTouchesTest();

#endif


code:
#include "ProgressActionsTest.h"
#include "../testResource.h"

static int sceneIdx = -1;

#define MAX_LAYER	3

CCLayer* nextAction();
CCLayer* backAction();
CCLayer* restartAction();

CCLayer* createLayer(int nIndex)
{
	switch(nIndex)
	{
		case 0: return new SpriteProgressToRadial();
		case 1: return new SpriteProgressToHorizontal();
		case 2: return new SpriteProgressToVertical();
	}

	return NULL;
}

CCLayer* nextAction()
{
	sceneIdx++;
	sceneIdx = sceneIdx % MAX_LAYER;

	CCLayer* pLayer = createLayer(sceneIdx);
	pLayer->autorelease();

	return pLayer;
}

CCLayer* backAction()
{
	sceneIdx--;
	int total = MAX_LAYER;
	if( sceneIdx < 0 )
		sceneIdx += total;

	CCLayer* pLayer = createLayer(sceneIdx);
	pLayer->autorelease();

	return pLayer;
}

CCLayer* restartAction()
{
	CCLayer* pLayer = createLayer(sceneIdx);
	pLayer->autorelease();

	return pLayer;
}

void ProgressActionsTestScene::runThisTest()
{
    addChild(nextAction());
    CCDirector::sharedDirector()->replaceScene(this);
}

//------------------------------------------------------------------
//
// SpriteDemo
//
//------------------------------------------------------------------
SpriteDemo::SpriteDemo(void)
{
}

SpriteDemo::~SpriteDemo(void)
{
}

std::string SpriteDemo::title()
{
	return "ProgressActionsTest";
}

std::string SpriteDemo::subtitle()
{
	return "";
}

void SpriteDemo::onEnter()
{
	CCLayer::onEnter();

    CCSize s = CCDirector::sharedDirector()->getWinSize();

	CCLabelTTF* label = CCLabelTTF::labelWithString(title().c_str(), "Arial", 18);
	addChild(label, 1);
	label->setPosition( CCPointMake(s.width/2, s.height-50) );

	std::string strSubtitle = subtitle();
	if( ! strSubtitle.empty() )
	{
		CCLabelTTF* l = CCLabelTTF::labelWithString(strSubtitle.c_str(), "Thonburi", 22);
		addChild(l, 1);
		l->setPosition( CCPointMake(s.width/2, s.height-80) );
	}

	CCMenuItemImage *item1 = CCMenuItemImage::itemFromNormalImage(s_pPathB1, s_pPathB2, this, menu_selector(SpriteDemo::backCallback) );
	CCMenuItemImage *item2 = CCMenuItemImage::itemFromNormalImage(s_pPathR1, s_pPathR2, this, menu_selector(SpriteDemo::restartCallback) );
	CCMenuItemImage *item3 = CCMenuItemImage::itemFromNormalImage(s_pPathF1, s_pPathF2, this, menu_selector(SpriteDemo::nextCallback) );

	CCMenu *menu = CCMenu::menuWithItems(item1, item2, item3, NULL);

	menu->setPosition( CCPointZero );
	item1->setPosition( CCPointMake( s.width/2 - 100,30) );
	item2->setPosition( CCPointMake( s.width/2, 30) );
	item3->setPosition( CCPointMake( s.width/2 + 100,30) );

	addChild(menu, 1);
}

void SpriteDemo::restartCallback(CCObject* pSender)
{
	CCScene* s = new ProgressActionsTestScene();
	s->addChild(restartAction());

	CCDirector::sharedDirector()->replaceScene(s);
    s->release();
}

void SpriteDemo::nextCallback(CCObject* pSender)
{
	CCScene* s = new ProgressActionsTestScene();
	s->addChild( nextAction() );
	CCDirector::sharedDirector()->replaceScene(s);
    s->release();
}

void SpriteDemo::backCallback(CCObject* pSender)
{
	CCScene* s = new ProgressActionsTestScene();
	s->addChild( backAction() );
	CCDirector::sharedDirector()->replaceScene(s);
    s->release();
}

//------------------------------------------------------------------
//
// SpriteProgressToRadial
//
//------------------------------------------------------------------
void SpriteProgressToRadial::onEnter()
{
	SpriteDemo::onEnter();

	CCSize s = CCDirector::sharedDirector()->getWinSize();

	CCProgressTo *to1 = CCProgressTo::actionWithDuration(2, 100);
	CCProgressTo *to2 = CCProgressTo::actionWithDuration(2, 100);

	CCProgressTimer *left = CCProgressTimer::progressWithFile(s_pPathSister1);
	left->setType( kCCProgressTimerTypeRadialCW );
	addChild(left);
	left->setPosition(CCPointMake(100, s.height/2));
	left->runAction( CCRepeatForever::actionWithAction(to1));

	CCProgressTimer *right = CCProgressTimer::progressWithFile(s_pPathBlock);
	right->setType( kCCProgressTimerTypeRadialCCW );
	addChild(right);
	right->setPosition(CCPointMake(s.width-100, s.height/2));
	right->runAction( CCRepeatForever::actionWithAction(to2));
}

std::string SpriteProgressToRadial::subtitle()
{
	return "ProgressTo Radial";
}

//------------------------------------------------------------------
//
// SpriteProgressToHorizontal
//
//------------------------------------------------------------------

void SpriteProgressToHorizontal::onEnter()
{
	SpriteDemo::onEnter();

	CCSize s = CCDirector::sharedDirector()->getWinSize();

	CCProgressTo *to1 = CCProgressTo::actionWithDuration(2, 100);
	CCProgressTo *to2 = CCProgressTo::actionWithDuration(2, 100);

	CCProgressTimer *left = CCProgressTimer::progressWithFile(s_pPathSister1);
	left->setType( kCCProgressTimerTypeHorizontalBarLR );
	addChild(left);
	left->setPosition(CCPointMake(100, s.height/2));
	left->runAction( CCRepeatForever::actionWithAction(to1));

	CCProgressTimer *right = CCProgressTimer::progressWithFile(s_pPathSister2);
	right->setType( kCCProgressTimerTypeHorizontalBarRL );
	addChild(right);
	right->setPosition(CCPointMake(s.width-100, s.height/2));
	right->runAction( CCRepeatForever::actionWithAction(to2));
}

std::string SpriteProgressToHorizontal::subtitle()
{
	return "ProgressTo Horizontal";
}

//------------------------------------------------------------------
//
// SpriteProgressToVertical
//
//------------------------------------------------------------------
void SpriteProgressToVertical::onEnter()
{
	SpriteDemo::onEnter();

	CCSize s = CCDirector::sharedDirector()->getWinSize();

	CCProgressTo *to1 = CCProgressTo::actionWithDuration(2, 100);
	CCProgressTo *to2 = CCProgressTo::actionWithDuration(2, 100);

	CCProgressTimer *left = CCProgressTimer::progressWithFile(s_pPathSister1);
	left->setType( kCCProgressTimerTypeVerticalBarBT );
	addChild(left);
	left->setPosition(CCPointMake(100, s.height/2));
	left->runAction( CCRepeatForever::actionWithAction(to1));

	CCProgressTimer *right = CCProgressTimer::progressWithFile(s_pPathSister2);
	right->setType( kCCProgressTimerTypeVerticalBarTB );
	addChild(right);
	right->setPosition(CCPointMake(s.width-100, s.height/2));
	right->runAction( CCRepeatForever::actionWithAction(to2));
}

std::string SpriteProgressToVertical::subtitle()
{
	return "ProgressTo Vertical";
}


code:
#ifndef _PROGRESS_ACTIONS_TEST_H_
#define _PROGRESS_ACTIONS_TEST_H_

#include "../testBasic.h"

class SpriteDemo : public CCLayer
{
public:
	SpriteDemo(void);
	~SpriteDemo(void);

	virtual std::string title();
	virtual std::string subtitle();
	virtual void onEnter();

	void restartCallback(CCObject* pSender);
	void nextCallback(CCObject* pSender);
	void backCallback(CCObject* pSender);
};

class SpriteProgressToRadial : public SpriteDemo
{
public:
	virtual void onEnter();
	virtual std::string subtitle();
};

class SpriteProgressToHorizontal : public SpriteDemo
{
public:
	virtual void onEnter();
	virtual std::string subtitle();
};

class SpriteProgressToVertical : public SpriteDemo
{
public:
	virtual void onEnter();
	virtual std::string subtitle();
};

class ProgressActionsTestScene : public TestScene
{
public:
    virtual void runThisTest();
};

#endif


code:
#include "CCConfiguration.h"
#include "RenderTextureTest.h"

// Test #1 by Jason Booth (slipster216)
// Test #3 by David Deaco (ddeaco)

static int sceneIdx = -1;

#define MAX_LAYER    4

CCLayer* createTestCase(int nIndex)
{

    switch(nIndex)
    {
    case 0: return new RenderTextureTest();
    case 1: return new RenderTextureIssue937();
	case 2: return new RenderTextureZbuffer();
	case 3: return new RenderTextureSave();
    }

    return NULL;
}

CCLayer* nextTestCase()
{
    sceneIdx++;
    sceneIdx = sceneIdx % MAX_LAYER;

    CCLayer* pLayer = createTestCase(sceneIdx);
    pLayer->autorelease();

    return pLayer;
}

CCLayer* backTestCase()
{
    sceneIdx--;
    int total = MAX_LAYER;
    if( sceneIdx < 0 )
        sceneIdx += total;

    CCLayer* pLayer = createTestCase(sceneIdx);
    pLayer->autorelease();

    return pLayer;
}

CCLayer* restartTestCase()
{
    CCLayer* pLayer = createTestCase(sceneIdx);
    pLayer->autorelease();

    return pLayer;
}

void RenderTextureTestDemo::onEnter()
{
    CCLayer::onEnter();
	CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCLabelTTF* label = CCLabelTTF::labelWithString(title().c_str(), "Arial", 28);
    addChild(label, 1);
    label->setPosition( ccp(s.width/2, s.height-50) );

    std::string strSubtitle = subtitle();
    if( ! strSubtitle.empty() )
    {
        CCLabelTTF* l = CCLabelTTF::labelWithString(strSubtitle.c_str(), "Thonburi", 16);
        addChild(l, 1);
        l->setPosition( ccp(s.width/2, s.height-80) );
    }

    CCMenuItemImage *item1 = CCMenuItemImage::itemFromNormalImage("Images/b1.png", "Images/b2.png", this, menu_selector(RenderTextureTestDemo::backCallback) );
    CCMenuItemImage *item2 = CCMenuItemImage::itemFromNormalImage("Images/r1.png","Images/r2.png", this, menu_selector(RenderTextureTestDemo::restartCallback) );
    CCMenuItemImage *item3 = CCMenuItemImage::itemFromNormalImage("Images/f1.png", "Images/f2.png", this, menu_selector(RenderTextureTestDemo::nextCallback) );

    CCMenu *menu = CCMenu::menuWithItems(item1, item2, item3, NULL);

    menu->setPosition( CCPointZero );
    item1->setPosition( ccp( s.width/2 - 100,30) );
    item2->setPosition( ccp( s.width/2, 30) );
    item3->setPosition( ccp( s.width/2 + 100,30) );

    addChild(menu, 1);
}

void RenderTextureTestDemo::restartCallback(CCObject* pSender)
{
    CCScene* s = new RenderTextureScene();
    s->addChild(restartTestCase());

    CCDirector::sharedDirector()->replaceScene(s);
    s->release();
}

void RenderTextureTestDemo::nextCallback(CCObject* pSender)
{
    CCScene* s = new RenderTextureScene();
    s->addChild( nextTestCase() );
    CCDirector::sharedDirector()->replaceScene(s);
    s->release();
}

void RenderTextureTestDemo::backCallback(CCObject* pSender)
{
    CCScene* s = new RenderTextureScene();
    s->addChild( backTestCase() );
    CCDirector::sharedDirector()->replaceScene(s);
    s->release();
}

std::string RenderTextureTestDemo::title()
{
    return "Render Texture Test";
}

std::string RenderTextureTestDemo::subtitle()
{
    return "";
}

RenderTextureTest::RenderTextureTest()
: m_brush(NULL)
{
	if (CCConfiguration::sharedConfiguration()->getGlesVersion() <= GLES_VER_1_0)
	{
		CCMessageBox("The Opengl ES version is lower than 1.1, and the test may not run correctly.", "Cocos2d-x Hint");
		return;
	}

    CCSize s = CCDirector::sharedDirector()->getWinSize();

    // create a render texture, this is what we're going to draw into
    m_target = CCRenderTexture::renderTextureWithWidthAndHeight(s.width, s.height);

	if (NULL == m_target)
	{
		return;
	}

    m_target->setPosition(ccp(s.width/2, s.height/2));

    // note that the render texture is a cocosnode, and contains a sprite of it's texture for convience,
    // so we can just parent it to the scene like any other cocos node
    addChild(m_target, 1);

    // create a brush image to draw into the texture with
    m_brush = CCSprite::spriteWithFile("Images/stars.png");
    m_brush->retain();

    ccBlendFunc bf = { GL_ONE, GL_ONE_MINUS_SRC_ALPHA };
    m_brush->setBlendFunc( bf);
    m_brush->setOpacity(20);
    setIsTouchEnabled(true);
}

RenderTextureTest::~RenderTextureTest()
{
	if (NULL != m_brush)
	{
		m_brush->release();
		m_brush = NULL;
	}
}

void RenderTextureTest::ccTouchesMoved(CCSet* touches, CCEvent* event)
{
    CCSetIterator it = touches->begin();
    CCTouch* touch = (CCTouch*)(*it);
    CCPoint start = touch->locationInView();
    start = CCDirector::sharedDirector()->convertToGL( start );
    CCPoint end = touch->previousLocationInView();
    end = CCDirector::sharedDirector()->convertToGL(end);

    // begin drawing to the render texture
    m_target->begin();

    // for extra points, we'll draw this smoothly from the last position and vary the sprite's
    // scale/rotation/offset
    float distance = ccpDistance(start, end);
    if (distance > 1)
    {
        int d = (int)distance;
        for (int i = 0; i < d; i++)
        {
            float difx = end.x - start.x;
            float dify = end.y - start.y;
            float delta = (float)i / distance;
            m_brush->setPosition(ccp(start.x + (difx * delta), start.y + (dify * delta)) );
            m_brush->setRotation( rand()%360 );
            float r = ((float)(rand()%50)/50.f) + 0.25f;
            m_brush->setScale( r );
            // Call visit to draw the brush, don't call draw..
            m_brush->visit();
        }
    }
    // finish drawing and return context back to the screen
    m_target->end(false);
}

void RenderTextureTest::ccTouchesEnded(CCSet* touches, CCEvent* event)
{
#if CC_ENABLE_CACHE_TEXTTURE_DATA

	CCSetIterator it;
	CCTouch* touch;

	for( it = touches->begin(); it != touches->end(); it++)
	{
		touch = (CCTouch*)(*it);

		if(!touch)
			break;

		CCPoint location = touch->locationInView();

		location = CCDirector::sharedDirector()->convertToGL(location);

		m_brush->setPosition(location);
		m_brush->setRotation( rand()%360 );
	}

	m_target->begin();
	m_brush->visit();
	m_target->end(true);
#endif
}

/**
* Impelmentation of RenderTextureSave
*/
RenderTextureSave::RenderTextureSave()
{
	CCSize s = CCDirector::sharedDirector()->getWinSize();

	// create a render texture, this is what we are going to draw into
	m_pTarget = CCRenderTexture::renderTextureWithWidthAndHeight(s.width, s.height);
	m_pTarget->retain();
	m_pTarget->setPosition(ccp(s.width / 2, s.height / 2));

	// note that the render texture is a CCNode, and contains a sprite of its texture for convience,
	// so we can just parent it to the scene like any other CCNode
	this->addChild(m_pTarget, -1);

	// create a brush image to draw into the texture with
	m_pBrush = CCSprite::spriteWithFile("Images/fire.png");
	m_pBrush->retain();
	m_pBrush->setOpacity(20);
	this->setIsTouchEnabled(true);

	// Save Image menu
	CCMenuItemFont::setFontSize(16);
	CCMenuItem *item1 = CCMenuItemFont::itemFromString("Save Image", this, menu_selector(RenderTextureSave::saveImage));
	CCMenuItem *item2 = CCMenuItemFont::itemFromString("Clear", this, menu_selector(RenderTextureSave::clearImage));
	CCMenu *menu = CCMenu::menuWithItems(item1, item2, NULL);
	this->addChild(menu);
	menu->alignItemsVertically();
	menu->setPosition(ccp(s.width - 80, s.height - 30));
}

string RenderTextureSave::title()
{
	return "Touch the screen";
}

string RenderTextureSave::subtitle()
{
	return "Press 'Save Image' to create an snapshot of the render texture";
}

void RenderTextureSave::clearImage(cocos2d::CCObject *pSender)
{
	m_pTarget->clear(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1());
}

void RenderTextureSave::saveImage(cocos2d::CCObject *pSender)
{
	static int counter = 0;

	char str[20];
	sprintf(str, "image-%d.png", counter);
	m_pTarget->saveBuffer(kCCImageFormatPNG, str);
	CCLOG("Image saved %s", str);

	counter++;
}

RenderTextureSave::~RenderTextureSave()
{
	m_pBrush->release();
	m_pTarget->release();
	CCTextureCache::sharedTextureCache()->removeUnusedTextures();
}

void RenderTextureSave::ccTouchesMoved(CCSet* touches, CCEvent* event)
{
	CCTouch *touch = (CCTouch *)touches->anyObject();
	CCPoint start = touch->locationInView();
	start = CCDirector::sharedDirector()->convertToGL(start);
	CCPoint end = touch->previousLocationInView();

	// begin drawing to the render texture
	m_pTarget->begin();

	// for extra points, we'll draw this smoothly from the last position and vary the sprite's
	// scale/rotation/offset
	float distance = ccpDistance(start, end);
	if (distance > 1)
	{
		int d = (int)distance;
		for (int i = 0; i < d; i++)
		{
			float difx = end.x - start.x;
			float dify = end.y - start.y;
			float delta = (float)i / distance;
			m_pBrush->setPosition(ccp(start.x + (difx * delta), start.y + (dify * delta)));
			m_pBrush->setRotation(rand() % 360);
			float r = (float)(rand() % 50 / 50.f) + 0.25f;
			m_pBrush->setScale(r);
			/*m_pBrush->setColor(ccc3(CCRANDOM_0_1() * 127 + 128, 255, 255));*/
			// Use CCRANDOM_0_1() will cause error when loading libtests.so on android, I don't know why.
			m_pBrush->setColor(ccc3(rand() % 127 + 128, 255, 255));
			// Call visit to draw the brush, don't call draw..
			m_pBrush->visit();
		}
	}

	// finish drawing and return context back to the screen
	m_pTarget->end();
}

/**
 * Impelmentation of RenderTextureIssue937
 */

RenderTextureIssue937::RenderTextureIssue937()
{
    /*
    *     1    2
    * A: A1   A2
    *
    * B: B1   B2
    *
    *  A1: premulti sprite
    *  A2: premulti render
    *
    *  B1: non-premulti sprite
    *  B2: non-premulti render
    */
    CCLayerColor *background = CCLayerColor::layerWithColor(ccc4f(200,200,200,255));
    addChild(background);

    CCSprite *spr_premulti = CCSprite::spriteWithFile("Images/fire.png");
    spr_premulti->setPosition(ccp(16,48));

    CCSprite *spr_nonpremulti = CCSprite::spriteWithFile("Images/fire.png");
    spr_nonpremulti->setPosition(ccp(16,16));

    /* A2 & B2 setup */
    CCRenderTexture *rend = CCRenderTexture::renderTextureWithWidthAndHeight(32, 64);

	if (NULL == rend)
	{
		return;
	}

    // It's possible to modify the RenderTexture blending function by
    //		[[rend sprite] setBlendFunc:(ccBlendFunc) {GL_ONE, GL_ONE_MINUS_SRC_ALPHA}];

    rend->begin();
    spr_premulti->visit();
    spr_nonpremulti->visit();
    rend->end();

    CCSize s = CCDirector::sharedDirector()->getWinSize();

    /* A1: setup */
    spr_premulti->setPosition(ccp(s.width/2-16, s.height/2+16));
    /* B1: setup */
    spr_nonpremulti->setPosition(ccp(s.width/2-16, s.height/2-16));

    rend->setPosition(ccp(s.width/2+16, s.height/2));

    addChild(spr_nonpremulti);
    addChild(spr_premulti);
    addChild(rend);
}

std::string RenderTextureIssue937::title()
{
    return "Testing issue #937";
}

std::string RenderTextureIssue937::subtitle()
{
    return "All images should be equal...";
}

void RenderTextureScene::runThisTest()
{
    CCLayer* pLayer = nextTestCase();
    addChild(pLayer);

    CCDirector::sharedDirector()->replaceScene(this);
}

/**
* Impelmentation of RenderTextureZbuffer
*/

RenderTextureZbuffer::RenderTextureZbuffer()
{
	this->setIsTouchEnabled(true);
	CCSize size = CCDirector::sharedDirector()->getWinSize();
	CCLabelTTF *label = CCLabelTTF::labelWithString("vertexZ = 50", "Marker Felt", 64);
	label->setPosition(ccp(size.width / 2, size.height * 0.25f));
	this->addChild(label);

	CCLabelTTF *label2 = CCLabelTTF::labelWithString("vertexZ = 0", "Marker Felt", 64);
	label2->setPosition(ccp(size.width / 2, size.height * 0.5f));
	this->addChild(label2);

	CCLabelTTF *label3 = CCLabelTTF::labelWithString("vertexZ = -50", "Marker Felt", 64);
	label3->setPosition(ccp(size.width / 2, size.height * 0.75f));
	this->addChild(label3);

	label->setVertexZ(50);
	label2->setVertexZ(0);
	label3->setVertexZ(-50);

	CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("Images/bugs/circle.plist");
	mgr = CCSpriteBatchNode::batchNodeWithFile("Images/bugs/circle.png", 9);
	this->addChild(mgr);
	sp1 = CCSprite::spriteWithSpriteFrameName("circle.png");
	sp2 = CCSprite::spriteWithSpriteFrameName("circle.png");
	sp3 = CCSprite::spriteWithSpriteFrameName("circle.png");
	sp4 = CCSprite::spriteWithSpriteFrameName("circle.png");
	sp5 = CCSprite::spriteWithSpriteFrameName("circle.png");
	sp6 = CCSprite::spriteWithSpriteFrameName("circle.png");
	sp7 = CCSprite::spriteWithSpriteFrameName("circle.png");
	sp8 = CCSprite::spriteWithSpriteFrameName("circle.png");
	sp9 = CCSprite::spriteWithSpriteFrameName("circle.png");

	mgr->addChild(sp1, 9);
	mgr->addChild(sp2, 8);
	mgr->addChild(sp3, 7);
	mgr->addChild(sp4, 6);
	mgr->addChild(sp5, 5);
	mgr->addChild(sp6, 4);
	mgr->addChild(sp7, 3);
	mgr->addChild(sp8, 2);
	mgr->addChild(sp9, 1);

	sp1->setVertexZ(400);
	sp2->setVertexZ(300);
	sp3->setVertexZ(200);
	sp4->setVertexZ(100);
	sp5->setVertexZ(0);
	sp6->setVertexZ(-100);
	sp7->setVertexZ(-200);
	sp8->setVertexZ(-300);
	sp9->setVertexZ(-400);

	sp9->setScale(2);
	sp9->setColor(ccYELLOW);
}

string RenderTextureZbuffer::title()
{
	return "Testing Z Buffer in Render Texture";
}

string RenderTextureZbuffer::subtitle()
{
	return "Touch screen. It should be green";
}

void RenderTextureZbuffer::ccTouchesBegan(cocos2d::CCSet *touches, cocos2d::CCEvent *event)
{
	CCSetIterator iter;
	CCTouch *touch;
	for (iter = touches->begin(); iter != touches->end(); ++iter)
	{
		touch = (CCTouch *)(*iter);
		CCPoint location = touch->locationInView();

		location = CCDirector::sharedDirector()->convertToGL(location);
		sp1->setPosition(location);
		sp2->setPosition(location);
		sp3->setPosition(location);
		sp4->setPosition(location);
		sp5->setPosition(location);
		sp6->setPosition(location);
		sp7->setPosition(location);
		sp8->setPosition(location);
		sp9->setPosition(location);
	}
}

void RenderTextureZbuffer::ccTouchesMoved(CCSet* touches, CCEvent* event)
{
	CCSetIterator iter;
	CCTouch *touch;
	for (iter = touches->begin(); iter != touches->end(); ++iter)
	{
		touch = (CCTouch *)(*iter);
		CCPoint location = touch->locationInView();

		location = CCDirector::sharedDirector()->convertToGL(location);
		sp1->setPosition(location);
		sp2->setPosition(location);
		sp3->setPosition(location);
		sp4->setPosition(location);
		sp5->setPosition(location);
		sp6->setPosition(location);
		sp7->setPosition(location);
		sp8->setPosition(location);
		sp9->setPosition(location);
	}
}

void RenderTextureZbuffer::ccTouchesEnded(CCSet* touches, CCEvent* event)
{
	this->renderScreenShot();
}

void RenderTextureZbuffer::renderScreenShot()
{
	CCRenderTexture *texture = CCRenderTexture::renderTextureWithWidthAndHeight(512, 512);
	if (NULL == texture)
	{
		return;
	}
	texture->setAnchorPoint(ccp(0, 0));
	texture->begin();

	this->visit();

	texture->end();

	CCSprite *sprite = CCSprite::spriteWithTexture(texture->getSprite()->getTexture());

	sprite->setPosition(ccp(256, 256));
	sprite->setOpacity(182);
	sprite->setFlipY(1);
	this->addChild(sprite, 999999);
	sprite->setColor(ccGREEN);

	sprite->runAction(CCSequence::actions(CCFadeTo::actionWithDuration(2, 0),
		                                  CCHide::action(),
		                                  NULL));
}


code:
#ifndef _RENDERTEXTURE_TEST_H_
#define _RENDERTEXTURE_TEST_H_

#include "cocos2d.h"
#include "../testBasic.h"

class RenderTextureTestDemo : public CCLayer
{
public:
	virtual void onEnter();
    virtual std::string title();
    virtual std::string subtitle();

    void restartCallback(CCObject* pSender);
    void nextCallback(CCObject* pSender);
    void backCallback(CCObject* pSender);
};

/**
@todo refactor the save image feature
*/
class RenderTextureTest : public RenderTextureTestDemo
{
public:
    RenderTextureTest();
    ~RenderTextureTest();
    virtual void ccTouchesMoved(CCSet* touches, CCEvent* event);
	virtual void ccTouchesEnded(CCSet* touches, CCEvent* event);

private:
    CCRenderTexture*	m_target;
    CCSprite*			m_brush;
};

class RenderTextureSave : public RenderTextureTestDemo
{
public:
	RenderTextureSave();
	~RenderTextureSave();
	virtual std::string title();
	virtual std::string subtitle();
	virtual void ccTouchesMoved(CCSet* touches, CCEvent* event);
	void clearImage(CCObject *pSender);
	void saveImage(CCObject *pSender);

private:
	CCRenderTexture *m_pTarget;
	CCSprite *m_pBrush;
};

class RenderTextureIssue937 : public RenderTextureTestDemo
{
public:
    RenderTextureIssue937();
    virtual std::string title();
    virtual std::string subtitle();
};

class RenderTextureScene : public TestScene
{
public:
    virtual void runThisTest();
};

class RenderTextureZbuffer : public RenderTextureTestDemo
{
public:
	RenderTextureZbuffer();

	virtual void ccTouchesMoved(CCSet* touches, CCEvent* event);
	virtual void ccTouchesBegan(CCSet* touches, CCEvent* event);
	virtual void ccTouchesEnded(CCSet* touches, CCEvent* event);
	virtual std::string title();
	virtual std::string subtitle();

	void renderScreenShot();

private:
	cocos2d::CCSpriteBatchNode *mgr;;

	cocos2d::CCSprite *sp1;
	cocos2d::CCSprite *sp2;
	cocos2d::CCSprite *sp3;
	cocos2d::CCSprite *sp4;
	cocos2d::CCSprite *sp5;
	cocos2d::CCSprite *sp6;
	cocos2d::CCSprite *sp7;
	cocos2d::CCSprite *sp8;
	cocos2d::CCSprite *sp9;
};

#endif


code:
#include "RotateWorldTest.h"
#include "../testResource.h"

//------------------------------------------------------------------
//
// TestLayer
//
//------------------------------------------------------------------
void TestLayer::onEnter()
{
	CCLayer::onEnter();

	float x,y;

	CCSize size = CCDirector::sharedDirector()->getWinSize();
	x = size.width;
	y = size.height;

	//CCMutableArray *array = [UIFont familyNames];
	//for( CCString *s in array )
	//	NSLog( s );
	CCLabelTTF* label = CCLabelTTF::labelWithString("cocos2d", "Tahoma", 64);

	label->setPosition( CCPointMake(x/2,y/2) );

	addChild(label);
}

//------------------------------------------------------------------
//
// SpriteLayer
//
//------------------------------------------------------------------
void SpriteLayer::onEnter()
{
	CCLayer::onEnter();

	float x,y;

	CCSize size = CCDirector::sharedDirector()->getWinSize();
	x = size.width;
	y = size.height;

	CCSprite* sprite = CCSprite::spriteWithFile(s_pPathGrossini);
	CCSprite* spriteSister1 = CCSprite::spriteWithFile(s_pPathSister1);
	CCSprite* spriteSister2 = CCSprite::spriteWithFile(s_pPathSister2);

	sprite->setScale(1.5f);
	spriteSister1->setScale(1.5f);
	spriteSister2->setScale(1.5f);

	sprite->setPosition(CCPointMake(x/2,y/2));
	spriteSister1->setPosition(CCPointMake(40,y/2));
	spriteSister2->setPosition(CCPointMake(x-40,y/2));

	CCAction *rot = CCRotateBy::actionWithDuration(16, -3600);

	addChild(sprite);
	addChild(spriteSister1);
	addChild(spriteSister2);

	sprite->runAction(rot);

	CCActionInterval *jump1 = CCJumpBy::actionWithDuration(4, CCPointMake(-400,0), 100, 4);
	CCActionInterval *jump2 = jump1->reverse();

	CCActionInterval *rot1 = CCRotateBy::actionWithDuration(4, 360*2);
	CCActionInterval *rot2 = rot1->reverse();

	spriteSister1->runAction(CCRepeat::actionWithAction( CCSequence::actions(jump2, jump1, NULL), 5 ));
	spriteSister2->runAction(CCRepeat::actionWithAction( CCSequence::actions((CCFiniteTimeAction *)(jump1->copy()->autorelease()), (CCFiniteTimeAction *)(jump2->copy()->autorelease()), NULL), 5 ));

	spriteSister1->runAction(CCRepeat::actionWithAction( CCSequence::actions(rot1, rot2, NULL), 5 ));
	spriteSister2->runAction(CCRepeat::actionWithAction( CCSequence::actions((CCFiniteTimeAction *)(rot2->copy()->autorelease()), (CCFiniteTimeAction *)(rot1->copy()->autorelease()), NULL), 5 ));
}

//------------------------------------------------------------------
//
// RotateWorldMainLayer
//
//------------------------------------------------------------------

void RotateWorldMainLayer::onEnter()
{
	CCLayer::onEnter();

	float x,y;

	CCSize size = CCDirector::sharedDirector()->getWinSize();
	x = size.width;
	y = size.height;

	CCNode* blue =  CCLayerColor::layerWithColor(ccc4f(0,0,255,255));
	CCNode* red =   CCLayerColor::layerWithColor(ccc4f(255,0,0,255));
	CCNode* green = CCLayerColor::layerWithColor(ccc4f(0,255,0,255));
	CCNode* white = CCLayerColor::layerWithColor(ccc4f(255,255,255,255));

	blue->setScale(0.5f);
	blue->setPosition(CCPointMake(-x/4,-y/4));
	blue->addChild( SpriteLayer::node() );

	red->setScale(0.5f);
	red->setPosition(CCPointMake(x/4,-y/4));

	green->setScale(0.5f);
	green->setPosition(CCPointMake(-x/4,y/4));
	green->addChild(TestLayer::node());

	white->setScale(0.5f);
	white->setPosition(CCPointMake(x/4,y/4));

	addChild(blue, -1);
	addChild(white);
	addChild(green);
	addChild(red);

	CCAction* rot = CCRotateBy::actionWithDuration(8, 720);

	blue->runAction(rot);
	red->runAction((CCAction *)(rot->copy()->autorelease()));
	green->runAction((CCAction *)(rot->copy()->autorelease()) );
	white->runAction((CCAction *)(rot->copy()->autorelease()) );
}

void RotateWorldTestScene::runThisTest()
{
    CCLayer* pLayer = RotateWorldMainLayer::node();

    addChild(pLayer);
    runAction( CCRotateBy::actionWithDuration(4, -360) );

    CCDirector::sharedDirector()->replaceScene(this);

}


code:
#ifndef _ROTATE_WORLD_TEST_H_
#define _ROTATE_WORLD_TEST_H_

#include "../testBasic.h"

class RotateWorldTestScene : public TestScene
{
public:
    virtual void runThisTest();
};

class SpriteLayer : public CCLayer
{
public:
	virtual void onEnter();
	static SpriteLayer* node()
	{
		SpriteLayer* pNode = new SpriteLayer();
		pNode->autorelease();

		return pNode;
	}
};

class TestLayer : public CCLayer
{
public:
	virtual void onEnter();

	static TestLayer* node()
	{
		TestLayer* pNode = new TestLayer();
		pNode->autorelease();

		return pNode;
	}
};

class RotateWorldMainLayer : public CCLayer
{
public:
	virtual void onEnter();

	static RotateWorldMainLayer* node()
	{
		RotateWorldMainLayer* pNode = new RotateWorldMainLayer();
		pNode->autorelease();

		return pNode;
	}
};

#endif


code:
#include "SceneTest.h"
#include "../testResource.h"

//------------------------------------------------------------------
//
// SceneTestLayer1
//
//------------------------------------------------------------------
enum
{
	MID_PUSHSCENE = 100,
	MID_PUSHSCENETRAN,
	MID_QUIT,
	MID_REPLACESCENE,
	MID_REPLACESCENETRAN,
	MID_GOBACK
};

SceneTestLayer1::SceneTestLayer1()
{
	CCMenuItemFont* item1 = CCMenuItemFont::itemFromString( "Test pushScene", this, menu_selector(SceneTestLayer1::onPushScene) );
	CCMenuItemFont* item2 = CCMenuItemFont::itemFromString( "Test pushScene w/transition", this, menu_selector(SceneTestLayer1::onPushSceneTran) );
	CCMenuItemFont* item3 = CCMenuItemFont::itemFromString( "Quit", this, menu_selector(SceneTestLayer1::onQuit) );

	CCMenu* menu = CCMenu::menuWithItems( item1, item2, item3, NULL );
	menu->alignItemsVertically();

	addChild( menu );

	CCSize s = CCDirector::sharedDirector()->getWinSize();
	CCSprite* sprite = CCSprite::spriteWithFile(s_pPathGrossini);
	addChild(sprite);
	sprite->setPosition( CCPointMake(s.width-40, s.height/2) );
	CCActionInterval* rotate = CCRotateBy::actionWithDuration(2, 360);
	CCAction* repeat = CCRepeatForever::actionWithAction(rotate);
	sprite->runAction(repeat);

	schedule( schedule_selector(SceneTestLayer1::testDealloc) );
}

void SceneTestLayer1::testDealloc(ccTime dt)
{
	//UXLOG("SceneTestLayer1:testDealloc");
}

void SceneTestLayer1::onEnter()
{
    CCLOG("SceneTestLayer1#onEnter");
    CCLayer::onEnter();
}

void SceneTestLayer1::onEnterTransitionDidFinish()
{
    CCLOG("SceneTestLayer1#onEnterTransitionDidFinish");
    CCLayer::onEnterTransitionDidFinish();
}

SceneTestLayer1::~SceneTestLayer1()
{
	//NSLog(@"SceneTestLayer1 - dealloc");
}

void SceneTestLayer1::onPushScene(CCObject* pSender)
{
	CCScene* scene = new SceneTestScene();
    CCLayer* pLayer = new SceneTestLayer2();
    scene->addChild( pLayer, 0 );
	CCDirector::sharedDirector()->pushScene( scene );
    scene->release();
    pLayer->release();
}

void SceneTestLayer1::onPushSceneTran(CCObject* pSender)
{
	CCScene* scene = new SceneTestScene();
    CCLayer* pLayer = new SceneTestLayer2();
    scene->addChild( pLayer, 0 );

	CCDirector::sharedDirector()->pushScene( CCTransitionSlideInT::transitionWithDuration(1, scene) );
    scene->release();
    pLayer->release();
}

void SceneTestLayer1::onQuit(CCObject* pSender)
{
	//getCocosApp()->exit();
	//CCDirector::sharedDirector()->popScene();

	//// HA HA... no more terminate on sdk v3.0
	//// http://developer.apple.com/iphone/library/qa/qa2008/qa1561.html
	//if( [[UIApplication sharedApplication] respondsToSelector:@selector(terminate)] )
	//	[[UIApplication sharedApplication] performSelector:@selector(terminate)];
}

//------------------------------------------------------------------
//
// SceneTestLayer2
//
//------------------------------------------------------------------

SceneTestLayer2::SceneTestLayer2()
{
	m_timeCounter = 0;

	CCMenuItemFont* item1 = CCMenuItemFont::itemFromString( "replaceScene", this,  menu_selector(SceneTestLayer2::onReplaceScene) );
	CCMenuItemFont* item2 = CCMenuItemFont::itemFromString( "replaceScene w/transition", this, menu_selector(SceneTestLayer2::onReplaceSceneTran) );
	CCMenuItemFont* item3 = CCMenuItemFont::itemFromString( "Go Back", this, menu_selector(SceneTestLayer2::onGoBack) );

	CCMenu* menu = CCMenu::menuWithItems( item1, item2, item3, NULL );
	menu->alignItemsVertically();

	addChild( menu );

	CCSize s = CCDirector::sharedDirector()->getWinSize();
	CCSprite* sprite = CCSprite::spriteWithFile(s_pPathGrossini);
	addChild(sprite);
	sprite->setPosition( CCPointMake(s.width-40, s.height/2) );
	CCActionInterval* rotate = CCRotateBy::actionWithDuration(2, 360);
	CCAction* repeat = CCRepeatForever::actionWithAction(rotate);
	sprite->runAction(repeat);

	schedule( schedule_selector(SceneTestLayer2::testDealloc) );
}

void SceneTestLayer2::testDealloc(ccTime dt)
{
	//m_timeCounter += dt;
	//if( m_timeCounter > 10 )
	//	onReplaceScene(this);
}

void SceneTestLayer2::onGoBack(CCObject* pSender)
{
	CCDirector::sharedDirector()->popScene();
}

void SceneTestLayer2::onReplaceScene(CCObject* pSender)
{
	CCScene* pScene = new SceneTestScene();
    CCLayer* pLayer = new SceneTestLayer3();
    pScene->addChild( pLayer, 0 );
	CCDirector::sharedDirector()->replaceScene( pScene );
    pScene->release();
    pLayer->release();
}

void SceneTestLayer2::onReplaceSceneTran(CCObject* pSender)
{
	CCScene* pScene = new SceneTestScene();
    CCLayer* pLayer = new SceneTestLayer3();
	pScene->addChild( pLayer, 0 );
	CCDirector::sharedDirector()->replaceScene( CCTransitionFlipX::transitionWithDuration(2, pScene) );
    pScene->release();
    pLayer->release();
}

//------------------------------------------------------------------
//
// SceneTestLayer3
//
//------------------------------------------------------------------

SceneTestLayer3::SceneTestLayer3()
{
	setIsTouchEnabled( true );
	CCLabelTTF* label = CCLabelTTF::labelWithString("Touch to popScene", "Marker Felt", 28);
	addChild(label);
	CCSize s = CCDirector::sharedDirector()->getWinSize();
	label->setPosition( CCPointMake(s.width/2, s.height/2) );

	CCSprite* sprite = CCSprite::spriteWithFile(s_pPathGrossini);
	addChild(sprite);
	sprite->setPosition( CCPointMake(s.width-40, s.height/2) );
	CCActionInterval* rotate = CCRotateBy::actionWithDuration(2, 360);
	CCAction* repeat = CCRepeatForever::actionWithAction(rotate);
	sprite->runAction(repeat);

	//schedule();
}

void SceneTestLayer3::testDealloc(ccTime dt)
{

}

void SceneTestLayer3::ccTouchesEnded(CCSet* touches, CCEvent* event)
{
//	static int i = 0;
	//UXLOG("SceneTestLayer3::ccTouchesEnded(%d)", ++i);
	CCDirector::sharedDirector()->popScene();
}

void SceneTestScene::runThisTest()
{
    CCLayer* pLayer = new SceneTestLayer1();
    addChild(pLayer);
    pLayer->release();

    CCDirector::sharedDirector()->replaceScene(this);
}


code:
#ifndef _SCENE_TEST_H_
#define _SCENE_TEST_H_

////----#include "cocos2d.h"
#include "../testBasic.h"

class SceneTestLayer1 : public CCLayer
{
public:
	SceneTestLayer1();
	~SceneTestLayer1();

    virtual void onEnter();
    virtual void onEnterTransitionDidFinish();

	void testDealloc(ccTime dt);
	void onPushScene(CCObject* pSender);
	void onPushSceneTran(CCObject* pSender);
	void onQuit(CCObject* pSender);

	//CREATE_NODE(SceneTestLayer1);
} ;

class SceneTestLayer2 : public CCLayer
{
	float	m_timeCounter;
public:
	SceneTestLayer2();

	void testDealloc(ccTime dt);
	void onGoBack(CCObject* pSender);
	void onReplaceScene(CCObject* pSender);
	void onReplaceSceneTran(CCObject* pSender);

	//CREATE_NODE(SceneTestLayer2);
} ;

class SceneTestLayer3 : public CCLayerColor
{
public:
	SceneTestLayer3();

	virtual void testDealloc(ccTime dt);

	virtual void ccTouchesEnded(CCSet* touches, CCEvent* event);

	//CREATE_NODE(SceneTestLayer3);
} ;

class SceneTestScene : public TestScene
{
public:
    virtual void runThisTest();
};

#endif


code:
#include "SchedulerTest.h"
#include "../testResource.h"

enum {
	kTagAnimationDance = 1,
};

#define MAX_TESTS           8
static int sceneIdx = -1;

CCLayer* nextSchedulerTest();
CCLayer* backSchedulerTest();
CCLayer* restartSchedulerTest();

CCLayer* createSchedulerTest(int nIndex)
{
    CCLayer* pLayer = NULL;

    switch (nIndex)
    {
    case 0:
        pLayer = new SchedulerAutoremove(); break;
    case 1:
        pLayer = new SchedulerPauseResume(); break;
    case 2:
        pLayer = new SchedulerUnscheduleAll(); break;
    case 3:
        pLayer = new SchedulerUnscheduleAllHard(); break;
    case 4:
        pLayer = new SchedulerSchedulesAndRemove(); break;
    case 5:
        pLayer = new SchedulerUpdate(); break;
    case 6:
        pLayer = new SchedulerUpdateAndCustom(); break;
    case 7:
        pLayer = new SchedulerUpdateFromCustom(); break;
    default:
        break;
    }
    pLayer->autorelease();

    return pLayer;
}

CCLayer* nextSchedulerTest()
{

	sceneIdx++;
	sceneIdx = sceneIdx % MAX_TESTS;

	return createSchedulerTest(sceneIdx);
}

CCLayer* backSchedulerTest()
{
	sceneIdx--;
	if( sceneIdx < 0 )
		sceneIdx += MAX_TESTS;

	return createSchedulerTest(sceneIdx);
}

CCLayer* restartSchedulerTest()
{
	return createSchedulerTest(sceneIdx);
}

//------------------------------------------------------------------
//
// SchedulerTestLayer
//
//------------------------------------------------------------------
void SchedulerTestLayer::onEnter()
{
    CCLayer::onEnter();

    CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCLabelTTF* label = CCLabelTTF::labelWithString(title().c_str(), "Arial", 32);
    addChild(label);
    label->setPosition(ccp(s.width/2, s.height-50));

    std::string subTitle = subtitle();
    if(! subTitle.empty())
    {
        CCLabelTTF* l = CCLabelTTF::labelWithString(subTitle.c_str(), "Thonburi", 16);
        addChild(l, 1);
        l->setPosition(ccp(s.width/2, s.height-80));
    }

    CCMenuItemImage *item1 = CCMenuItemImage::itemFromNormalImage("Images/b1.png", "Images/b2.png", this, menu_selector(SchedulerTestLayer::backCallback));
    CCMenuItemImage *item2 = CCMenuItemImage::itemFromNormalImage("Images/r1.png","Images/r2.png", this, menu_selector(SchedulerTestLayer::restartCallback) );
    CCMenuItemImage *item3 = CCMenuItemImage::itemFromNormalImage("Images/f1.png", "Images/f2.png", this, menu_selector(SchedulerTestLayer::nextCallback) );

    CCMenu *menu = CCMenu::menuWithItems(item1, item2, item3, NULL);
    menu->setPosition(CCPointZero);
    item1->setPosition(ccp( s.width/2 - 100,30));
    item2->setPosition(ccp( s.width/2, 30));
    item3->setPosition(ccp( s.width/2 + 100,30));

    addChild(menu, 1);
}

void SchedulerTestLayer::backCallback(CCObject* pSender)
{
    CCScene* pScene = new SchedulerTestScene();
    CCLayer* pLayer = backSchedulerTest();

    pScene->addChild(pLayer);
    CCDirector::sharedDirector()->replaceScene(pScene);
    pScene->release();
}

void SchedulerTestLayer::nextCallback(CCObject* pSender)
{
    CCScene* pScene = new SchedulerTestScene();
    CCLayer* pLayer = nextSchedulerTest();

    pScene->addChild(pLayer);
    CCDirector::sharedDirector()->replaceScene(pScene);
    pScene->release();
}

void SchedulerTestLayer::restartCallback(CCObject* pSender)
{
    CCScene* pScene = new SchedulerTestScene();
    CCLayer* pLayer = restartSchedulerTest();

    pScene->addChild(pLayer);
    CCDirector::sharedDirector()->replaceScene(pScene);
    pScene->release();
}

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;
}

void SchedulerAutoremove::autoremove(ccTime dt)
{
    accum += dt;
    CCLOG("Time: %f", accum);

    if( accum > 3 )
    {
        unschedule(schedule_selector(SchedulerAutoremove::autoremove));
        CCLOG("scheduler removed");
    }
}

void SchedulerAutoremove::tick(ccTime dt)
{
    CCLOG("This scheduler should not be removed");
}

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);
}

void SchedulerPauseResume::tick1(ccTime dt)
{
    CCLOG("tick1");
}

void SchedulerPauseResume::tick2(ccTime dt)
{
    CCLOG("tick2");
}

void SchedulerPauseResume::pause(ccTime dt)
{
    CCScheduler::sharedScheduler()->pauseTarget(this);
}

std::string SchedulerPauseResume::title()
{
    return "Pause / Resume";
}

std::string SchedulerPauseResume::subtitle()
{
    return "Scheduler should be paused after 3 seconds. See console";
}

//------------------------------------------------------------------
//
// 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);
}

void SchedulerUnscheduleAll::tick1(ccTime dt)
{
    CCLOG("tick1");
}

void SchedulerUnscheduleAll::tick2(ccTime dt)
{
    CCLOG("tick2");
}

void SchedulerUnscheduleAll::tick3(ccTime dt)
{
    CCLOG("tick3");
}

void SchedulerUnscheduleAll::tick4(ccTime dt)
{
    CCLOG("tick4");
}

void SchedulerUnscheduleAll::unscheduleAll(ccTime dt)
{
    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();

    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);
}

void SchedulerUnscheduleAllHard::tick1(ccTime dt)
{
    CCLOG("tick1");
}

void SchedulerUnscheduleAllHard::tick2(ccTime dt)
{
    CCLOG("tick2");
}

void SchedulerUnscheduleAllHard::tick3(ccTime dt)
{
    CCLOG("tick3");
}

void SchedulerUnscheduleAllHard::tick4(ccTime dt)
{
    CCLOG("tick4");
}

void SchedulerUnscheduleAllHard::unscheduleAll(ccTime dt)
{
    CCScheduler::sharedScheduler()->unscheduleAllSelectors();
}

std::string SchedulerUnscheduleAllHard::title()
{
    return "Unschedule All selectors #2";
}

std::string SchedulerUnscheduleAllHard::subtitle()
{
    return "Unschedules all selectors after 4s. Uses CCScheduler. See console";
}

//------------------------------------------------------------------
//
// 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);
}

void SchedulerSchedulesAndRemove::tick1(ccTime dt)
{
    CCLOG("tick1");
}

void SchedulerSchedulesAndRemove::tick2(ccTime dt)
{
    CCLOG("tick2");
}

void SchedulerSchedulesAndRemove::tick3(ccTime dt)
{
    CCLOG("tick3");
}

void SchedulerSchedulesAndRemove::tick4(ccTime dt)
{
    CCLOG("tick4");
}

std::string SchedulerSchedulesAndRemove::title()
{
    return "Schedule from Schedule";
}

std::string SchedulerSchedulesAndRemove::subtitle()
{
    return "Will unschedule and schedule selectors in 4s. See console";
}

void SchedulerSchedulesAndRemove::scheduleAndUnschedule(ccTime dt)
{
    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
//
//------------------------------------------------------------------
void TestNode::initWithString(CCString* pStr, int priority)
{
    m_pstring = pStr;
    m_pstring->retain();
    scheduleUpdateWithPriority(priority);
}

TestNode::~TestNode()
{
    m_pstring->release();
}

//------------------------------------------------------------------
//
// SchedulerUpdate
//
//------------------------------------------------------------------
void SchedulerUpdate::onEnter()
{
    SchedulerTestLayer::onEnter();

    TestNode* d = new TestNode();
    CCString* pStr = new CCString("---");
    d->initWithString(pStr, 50);
    pStr->release();
    addChild(d);
    d->release();

    TestNode* b = new TestNode();
    pStr = new CCString("3rd");
    b->initWithString(pStr, 0);
    pStr->release();
    addChild(b);
    b->release();

    TestNode* a = new TestNode();
    pStr = new CCString("1st");
    a->initWithString(pStr, -10);
    pStr->release();
    addChild(a);
    a->release();

    TestNode* c = new TestNode();
    pStr = new CCString("4th");
    c->initWithString(pStr, 10);
    pStr->release();
    addChild(c);
    c->release();

    TestNode* e = new TestNode();
    pStr = new CCString("5th");
    e->initWithString(pStr, 20);
    pStr->release();
    addChild(e);
    e->release();

    TestNode* f = new TestNode();
    pStr = new CCString("2nd");
    f->initWithString(pStr, -5);
    pStr->release();
    addChild(f);
    f->release();

    schedule(schedule_selector(SchedulerUpdate::removeUpdates), 4.0f);
}

void SchedulerUpdate::removeUpdates(ccTime dt)
{
    CCArray* children = getChildren();
    CCNode* pNode;
    CCObject* pObject;
    CCARRAY_FOREACH(children, pObject)
    {
        pNode = (CCNode*)pObject;

        if (! pNode)
        {
            break;
        }
        pNode->unscheduleAllSelectors();
    }
}

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);
}

void SchedulerUpdateAndCustom::update(ccTime dt)
{
    CCLOG("update called:%f", dt);
}

void SchedulerUpdateAndCustom::tick(ccTime dt)
{
    CCLOG("custom selector called:%f",dt);
}

void SchedulerUpdateAndCustom::stopSelectors(ccTime dt)
{
    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);
}

void SchedulerUpdateFromCustom::update(ccTime dt)
{
    CCLOG("update called:%f", dt);
}

void SchedulerUpdateFromCustom::schedUpdate(ccTime dt)
{
    unschedule(schedule_selector(SchedulerUpdateFromCustom::schedUpdate));
    scheduleUpdate();
    schedule(schedule_selector(SchedulerUpdateFromCustom::stopUpdate), 2.0f);
}

void SchedulerUpdateFromCustom::stopUpdate(ccTime dt)
{
    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";
}

//------------------------------------------------------------------
//
// RescheduleSelector
//
//------------------------------------------------------------------
void RescheduleSelector::onEnter()
{
    SchedulerTestLayer::onEnter();

    m_fInterval = 1.0f;
    m_nTicks    = 0;
    schedule(schedule_selector(RescheduleSelector::schedUpdate), m_fInterval);
}

std::string RescheduleSelector::title()
{
    return "Reschedule Selector";
}

std::string RescheduleSelector::subtitle()
{
    return "Interval is 1 second, then 2, then 3...";
}

void RescheduleSelector::schedUpdate(ccTime dt)
{
    m_nTicks++;

    CCLOG("schedUpdate: %.2f", dt);
    if ( m_nTicks > 3 )
    {
        m_fInterval += 1.0f;
        schedule(schedule_selector(RescheduleSelector::schedUpdate), m_fInterval);
        m_nTicks = 0;
    }
}

//------------------------------------------------------------------
//
// SchedulerTestScene
//
//------------------------------------------------------------------
void SchedulerTestScene::runThisTest()
{
    CCLayer* pLayer = nextSchedulerTest();
    addChild(pLayer);

    CCDirector::sharedDirector()->replaceScene(this);
}


code:
#ifndef _SCHEDULER_TEST_H_
#define _SCHEDULER_TEST_H_

#include "cocos2d.h"
#include "../testBasic.h"
//#import "cocos2d.h"

class SchedulerTestLayer : public CCLayer
{
public:
    virtual void onEnter();

    virtual std::string title();
    virtual std::string subtitle();

    void backCallback(CCObject* pSender);
    void nextCallback(CCObject* pSender);
    void restartCallback(CCObject* pSender);
};

// class SchedulerTestLayer : CCLayer
// {
// }
// -(CCString*) title;
// -(CCString*) subtitle;
//
// -(void) backCallback:(id) sender;
// -(void) nextCallback:(id) sender;
// -(void) restartCallback:(id) sender;
//

class SchedulerAutoremove : public SchedulerTestLayer
{
public:
    virtual void onEnter();
    virtual std::string title();
    virtual std::string subtitle();

    void autoremove(ccTime dt);
    void tick(ccTime dt);
private:
	ccTime accum;
};

class SchedulerPauseResume : public SchedulerTestLayer
{
public:
    virtual void onEnter();
    virtual std::string title();
    virtual std::string subtitle();

    void tick1(ccTime dt);
    void tick2(ccTime dt);
    void pause(ccTime dt);
};

class SchedulerUnscheduleAll : public SchedulerTestLayer
{
public:
    virtual void onEnter();
    virtual std::string title();
    virtual std::string subtitle();

    void tick1(ccTime dt);
    void tick2(ccTime dt);
    void tick3(ccTime dt);
    void tick4(ccTime dt);
    void unscheduleAll(ccTime dt);
};

class SchedulerUnscheduleAllHard : public SchedulerTestLayer
{
public:
    virtual void onEnter();
    virtual std::string title();
    virtual std::string subtitle();

    void tick1(ccTime dt);
    void tick2(ccTime dt);
    void tick3(ccTime dt);
    void tick4(ccTime dt);
    void unscheduleAll(ccTime dt);
};

class SchedulerSchedulesAndRemove : public SchedulerTestLayer
{
public:
    virtual void onEnter();
    virtual std::string title();
    virtual std::string subtitle();

    void tick1(ccTime dt);
    void tick2(ccTime dt);
    void tick3(ccTime dt);
    void tick4(ccTime dt);
    void scheduleAndUnschedule(ccTime dt);
};

class SchedulerUpdate : public SchedulerTestLayer
{
public:
    virtual void onEnter();
    virtual std::string title();
    virtual std::string subtitle();

    void removeUpdates(ccTime dt);
};

class SchedulerUpdateAndCustom : public SchedulerTestLayer
{
public:
    virtual void onEnter();
    virtual std::string title();
    virtual std::string subtitle();

    void update(ccTime dt);
    void tick(ccTime dt);
    void stopSelectors(ccTime dt);
};

class SchedulerUpdateFromCustom : public SchedulerTestLayer
{
public:
    virtual void onEnter();
    virtual std::string title();
    virtual std::string subtitle();

    void update(ccTime dt);
    void schedUpdate(ccTime dt);
    void stopUpdate(ccTime dt);
};

class TestNode : public CCNode
{
public:
    ~TestNode();

    void initWithString(CCString* pStr, int priority);
private:
    CCString* m_pstring;
};

class RescheduleSelector : public SchedulerTestLayer
{
public:
    virtual void onEnter();
    virtual std::string title();
    virtual std::string subtitle();

    void schedUpdate(ccTime dt);
private:
    float m_fInterval;
    int   m_nTicks;
};

class SchedulerTestScene : public TestScene
{
public:
    virtual void runThisTest();
};

#endif