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

enum {
	kTagTileMap = 1,
	kTagSpriteManager = 1,
	kTagAnimation1 = 1,
	kTagBitmapAtlas1 = 1,
	kTagBitmapAtlas2 = 2,
	kTagBitmapAtlas3 = 3,
};

enum {
	kTagSprite1,
	kTagSprite2,
	kTagSprite3,
	kTagSprite4,
	kTagSprite5,
	kTagSprite6,
	kTagSprite7,
	kTagSprite8,
};

//------------------------------------------------------------------
//
// AtlasDemo
//
//------------------------------------------------------------------

enum
{
	IDC_NEXT = 100,
	IDC_BACK,
	IDC_RESTART
};

CCLayer* nextAtlasAction();
CCLayer* backAtlasAction();
CCLayer* restartAtlasAction();

static int sceneIdx = -1;

#define MAX_LAYER	18

CCLayer* createAtlasLayer(int nIndex)
{
	switch(nIndex)
	{
		case 0: return new LabelAtlasTest();
		case 1: return new LabelAtlasColorTest();
		case 2: return new Atlas3();
		case 3: return new Atlas4();
		case 4: return new Atlas5();
		case 5: return new Atlas6();
		case 6: return new AtlasBitmapColor();
		case 7: return new AtlasFastBitmap();
        case 8: return new BitmapFontMultiLine();
        case 9: return new LabelsEmpty();
        case 10: return new LabelBMFontHD();
        case 11: return new LabelAtlasHD();
        case 12: return new LabelGlyphDesigner();

        // Not a label test. Should be moved to Atlas test
        case 13: return new Atlas1();
		case 14: return new LabelTTFTest();
		case 15: return new LabelTTFMultiline();
		case 16: return new LabelTTFChinese();
        case 17: return new LabelBMFontChinese();
	}

	return NULL;
}

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

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

	return pLayer;
}

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

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

	return pLayer;
}

CCLayer* restartAtlasAction()
{
	CCLayer* pLayer = createAtlasLayer(sceneIdx);
	pLayer->autorelease();

	return pLayer;
}

AtlasDemo::AtlasDemo(void)
{
}

AtlasDemo::~AtlasDemo(void)
{
}

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

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

void AtlasDemo::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(s_pPathB1, s_pPathB2, this, menu_selector(AtlasDemo::backCallback) );
	CCMenuItemImage *item2 = CCMenuItemImage::itemFromNormalImage(s_pPathR1, s_pPathR2, this, menu_selector(AtlasDemo::restartCallback) );
	CCMenuItemImage *item3 = CCMenuItemImage::itemFromNormalImage(s_pPathF1, s_pPathF2, this, menu_selector(AtlasDemo::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 AtlasDemo::restartCallback(CCObject* pSender)
{
	CCScene* s = new AtlasTestScene();
	s->addChild(restartAtlasAction());

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

void AtlasDemo::nextCallback(CCObject* pSender)
{
	CCScene* s = new AtlasTestScene();
	s->addChild( nextAtlasAction() );
	CCDirector::sharedDirector()->replaceScene(s);
    s->release();
}

void AtlasDemo::backCallback(CCObject* pSender)
{
	CCScene* s = new AtlasTestScene();
	s->addChild( backAtlasAction() );
	CCDirector::sharedDirector()->replaceScene(s);
    s->release();
}

//------------------------------------------------------------------
//
// Atlas1
//
//------------------------------------------------------------------
Atlas1::Atlas1()
{
	m_textureAtlas = CCTextureAtlas::textureAtlasWithFile(s_AtlasTest, 3); m_textureAtlas->retain();

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

	//
	// Notice: u,v tex coordinates are inverted
	//
	ccV3F_C4B_T2F_Quad quads[] =
	{
		{
			{{0,0,0},ccc4f(0,0,255,255),{0.0f,1.0f},},				// bottom left
			{{s.width,0,0},ccc4f(0,0,255,0),{1.0f,1.0f},},			// bottom right
			{{0,s.height,0},ccc4f(0,0,255,0),{0.0f,0.0f},},			// top left
			{{s.width,s.height,0},{0,0,255,255},{1.0f,0.0f},},	// top right
		},
		{
			{{40,40,0},ccc4f(255,255,255,255),{0.0f,0.2f},},			// bottom left
			{{120,80,0},ccc4f(255,0,0,255),{0.5f,0.2f},},			// bottom right
			{{40,160,0},ccc4f(255,255,255,255),{0.0f,0.0f},},		// top left
			{{160,160,0},ccc4f(0,255,0,255),{0.5f,0.0f},},			// top right
		},

		{
			{{s.width/2,40,0},ccc4f(255,0,0,255),{0.0f,1.0f},},		// bottom left
			{{s.width,40,0},ccc4f(0,255,0,255),{1.0f,1.0f},},		// bottom right
			{{s.width/2-50,200,0},ccc4f(0,0,255,255),{0.0f,0.0f},},		// top left
			{{s.width,100,0},ccc4f(255,255,0,255),{1.0f,0.0f},},		// top right
		},

	};

	for( int i=0;i<3;i++)
	{
		m_textureAtlas->updateQuad(&quads[i], i);
	}
}

Atlas1::~Atlas1()
{
	m_textureAtlas->release();
}

void Atlas1::draw()
{
	// GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
	// GL_TEXTURE_2D

	m_textureAtlas->drawQuads();

//	[textureAtlas drawNumberOfQuads:3];

}

std::string Atlas1::title()
{
	return "CCTextureAtlas";
}

std::string Atlas1::subtitle()
{
	return "Manual creation of CCTextureAtlas";
}

//------------------------------------------------------------------
//
// LabelAtlasTest
//
//------------------------------------------------------------------

LabelAtlasTest::LabelAtlasTest()
{
	m_time = 0;

	CCLabelAtlas* label1 = CCLabelAtlas::labelWithString("123 Test", "fonts/tuffy_bold_italic-charmap.png", 48, 64, ' ');
	addChild(label1, 0, kTagSprite1);
	label1->setPosition( ccp(10,100) );
	label1->setOpacity( 200 );

	CCLabelAtlas *label2 = CCLabelAtlas::labelWithString("0123456789", "fonts/tuffy_bold_italic-charmap.png", 48, 64, ' ');
	addChild(label2, 0, kTagSprite2);
	label2->setPosition( ccp(10,200) );
	label2->setOpacity( 32 );

	schedule(schedule_selector(LabelAtlasTest::step));

}

void LabelAtlasTest::step(ccTime dt)
{
	m_time += dt;
    char string[12] = {0};
    sprintf(string, "%2.2f Test", m_time);
	//string.format("%2.2f Test", m_time);

	CCLabelAtlas* label1 = (CCLabelAtlas*)getChildByTag(kTagSprite1);
	label1->setString(string);

	CCLabelAtlas*label2 = (CCLabelAtlas*)getChildByTag(kTagSprite2);
    sprintf(string, "%d", (int)m_time);
	//string.format("%d", (int)m_time);
	label2->setString(string);
}

std::string LabelAtlasTest::title()
{
	return "LabelAtlas";
}

std::string LabelAtlasTest::subtitle()
{
	return "Updating label should be fast";
}

//------------------------------------------------------------------
//
// LabelAtlasColorTest
//
//------------------------------------------------------------------
LabelAtlasColorTest::LabelAtlasColorTest()
{
	CCLabelAtlas* label1 = CCLabelAtlas::labelWithString("123 Test", "fonts/tuffy_bold_italic-charmap.png", 48, 64, ' ');
	addChild(label1, 0, kTagSprite1);
	label1->setPosition( ccp(10,100) );
	label1->setOpacity( 200 );

	CCLabelAtlas* label2 = CCLabelAtlas::labelWithString("0123456789", "fonts/tuffy_bold_italic-charmap.png", 48, 64, ' ');
	addChild(label2, 0, kTagSprite2);
	label2->setPosition( ccp(10,200) );
	label2->setColor( ccRED );

	CCActionInterval* fade = CCFadeOut::actionWithDuration(1.0f);
	CCActionInterval* fade_in = fade->reverse();
	CCFiniteTimeAction* seq = CCSequence::actions(fade, fade_in, NULL);
	CCAction* repeat = CCRepeatForever::actionWithAction( (CCActionInterval*)seq );
	label2->runAction( repeat );

	m_time = 0;

	schedule( schedule_selector(LabelAtlasColorTest::step) ); //:@selector(step:)];
}

void LabelAtlasColorTest::step(ccTime dt)
{
	m_time += dt;
    char string[12] = {0};
    sprintf(string, "%2.2f Test", m_time);
	//std::string string = std::string::stringWithFormat("%2.2f Test", m_time);
	CCLabelAtlas* label1 = (CCLabelAtlas*)getChildByTag(kTagSprite1);
	label1->setString(string);

	CCLabelAtlas* label2 = (CCLabelAtlas*)getChildByTag(kTagSprite2);
    sprintf(string, "%d", (int)m_time);
	label2->setString( string );
}

std::string LabelAtlasColorTest::title()
{
	return "CCLabelAtlas";
}

std::string LabelAtlasColorTest::subtitle()
{
	return "Opacity + Color should work at the same time";
}

//------------------------------------------------------------------
//
// Atlas3
//
// Use any of these editors to generate BMFonts:
//     http://glyphdesigner.71squared.com/ (Commercial, Mac OS X)
//     http://www.n4te.com/hiero/hiero.jnlp (Free, Java)
//     http://slick.cokeandcode.com/demos/hiero.jnlp (Free, Java)
//     http://www.angelcode.com/products/bmfont/ (Free, Windows only)
//
//------------------------------------------------------------------
Atlas3::Atlas3()
{
	m_time = 0;

	CCLayerColor* col = CCLayerColor::layerWithColor( ccc4f(128,128,128,255) );
	addChild(col, -10);

	CCLabelBMFont* label1 = CCLabelBMFont::labelWithString("Test",  "fonts/bitmapFontTest2.fnt");

	// testing anchors
	label1->setAnchorPoint( ccp(0,0) );
	addChild(label1, 0, kTagBitmapAtlas1);
	CCActionInterval* fade = CCFadeOut::actionWithDuration(1.0f);
	CCActionInterval* fade_in = fade->reverse();
	CCFiniteTimeAction* seq = CCSequence::actions(fade, fade_in, NULL);
	CCAction* repeat = CCRepeatForever::actionWithAction((CCActionInterval*)seq);
	label1->runAction(repeat);

	// VERY IMPORTANT
	// color and opacity work OK because bitmapFontAltas2 loads a BMP image (not a PNG image)
	// If you want to use both opacity and color, it is recommended to use NON premultiplied images like BMP images
	// Of course, you can also tell XCode not to compress PNG images, but I think it doesn't work as expected
	CCLabelBMFont *label2 = CCLabelBMFont::labelWithString("Test", "fonts/bitmapFontTest2.fnt");
	// testing anchors
	label2->setAnchorPoint( ccp(0.5f, 0.5f) );
	label2->setColor( ccRED );
	addChild(label2, 0, kTagBitmapAtlas2);
	label2->runAction( (CCAction*)(repeat->copy()->autorelease()) );

	CCLabelBMFont* label3 = CCLabelBMFont::labelWithString("Test", "fonts/bitmapFontTest2.fnt");
	// testing anchors
	label3->setAnchorPoint( ccp(1,1) );
	addChild(label3, 0, kTagBitmapAtlas3);

	CCSize s = CCDirector::sharedDirector()->getWinSize();
	label1->setPosition( ccp( 0,0) );
	label2->setPosition( ccp( s.width/2, s.height/2) );
	label3->setPosition( ccp( s.width, s.height) );

	schedule( schedule_selector(Atlas3::step) );//:@selector(step:)];
}

void Atlas3::step(ccTime dt)
{
	m_time += dt;
	//std::string string;
    char string[15] = {0};
    sprintf(string, "%2.2f Test j", m_time);
	//string.format("%2.2f Test j", m_time);

	CCLabelBMFont *label1 = (CCLabelBMFont*) getChildByTag(kTagBitmapAtlas1);
	label1->setString(string);

	CCLabelBMFont *label2 = (CCLabelBMFont*) getChildByTag(kTagBitmapAtlas2);
	label2->setString(string);

	CCLabelBMFont *label3 = (CCLabelBMFont*) getChildByTag(kTagBitmapAtlas3);
	label3->setString(string);

}

std::string Atlas3::title()
{
	return "CCLabelBMFont";
}

std::string Atlas3::subtitle()
{
	return "Testing alignment. Testing opacity + tint";
}

//------------------------------------------------------------------
//
// Atlas4
//
// Use any of these editors to generate BMFonts:
//     http://glyphdesigner.71squared.com/ (Commercial, Mac OS X)
//     http://www.n4te.com/hiero/hiero.jnlp (Free, Java)
//     http://slick.cokeandcode.com/demos/hiero.jnlp (Free, Java)
//     http://www.angelcode.com/products/bmfont/ (Free, Windows only)
//
//------------------------------------------------------------------
Atlas4::Atlas4()
{
	m_time = 0;

	// Upper Label
	CCLabelBMFont *label = CCLabelBMFont::labelWithString("Bitmap Font Atlas", "fonts/bitmapFontTest.fnt");
	addChild(label);

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

	label->setPosition( ccp(s.width/2, s.height/2) );
	label->setAnchorPoint( ccp(0.5f, 0.5f) );

	CCSprite* BChar = (CCSprite*) label->getChildByTag(0);
	CCSprite* FChar = (CCSprite*) label->getChildByTag(7);
	CCSprite* AChar = (CCSprite*) label->getChildByTag(12);

	CCActionInterval* rotate = CCRotateBy::actionWithDuration(2, 360);
	CCAction* rot_4ever = CCRepeatForever::actionWithAction(rotate);

	CCActionInterval* scale = CCScaleBy::actionWithDuration(2, 1.5f);
	CCActionInterval* scale_back = scale->reverse();
	CCFiniteTimeAction* scale_seq = CCSequence::actions(scale, scale_back,NULL);
	CCAction* scale_4ever = CCRepeatForever::actionWithAction((CCActionInterval*)scale_seq);

	CCActionInterval* jump = CCJumpBy::actionWithDuration(0.5f, CCPointZero, 60, 1);
	CCAction* jump_4ever = CCRepeatForever::actionWithAction(jump);

	CCActionInterval* fade_out = CCFadeOut::actionWithDuration(1);
	CCActionInterval* fade_in = CCFadeIn::actionWithDuration(1);
	CCFiniteTimeAction* seq = CCSequence::actions(fade_out, fade_in, NULL);
	CCAction* fade_4ever = CCRepeatForever::actionWithAction((CCActionInterval*)seq);

	BChar->runAction(rot_4ever);
	BChar->runAction(scale_4ever);
	FChar->runAction(jump_4ever);
	AChar->runAction(fade_4ever);

	// Bottom Label
	CCLabelBMFont *label2 = CCLabelBMFont::labelWithString("00.0", "fonts/bitmapFontTest.fnt");
	addChild(label2, 0, kTagBitmapAtlas2);
	label2->setPosition( ccp(s.width/2.0f, 80) );

	CCSprite* lastChar = (CCSprite*) label2->getChildByTag(3);
	lastChar->runAction( (CCAction*)(rot_4ever->copy()->autorelease()) );

	schedule( schedule_selector(Atlas4::step), 0.1f);
}

void Atlas4::draw()
{
	CCSize s = CCDirector::sharedDirector()->getWinSize();
	ccDrawLine( ccp(0, s.height/2), ccp(s.width, s.height/2) );
	ccDrawLine( ccp(s.width/2, 0), ccp(s.width/2, s.height) );
}

void Atlas4::step(ccTime dt)
{
	m_time += dt;
    char string[10] = {0};
    sprintf(string, "%04.1f", m_time);
// 	std::string string;
// 	string.format("%04.1f", m_time);

	CCLabelBMFont* label1 = (CCLabelBMFont*) getChildByTag(kTagBitmapAtlas2);
	label1->setString(string);
}

std::string Atlas4::title()
{
	return "CCLabelBMFont";
}

std::string Atlas4::subtitle()
{
	return "Using fonts as CCSprite objects. Some characters should rotate.";
}

//------------------------------------------------------------------
//
// Atlas5
//
// Use any of these editors to generate BMFonts:
//     http://glyphdesigner.71squared.com/ (Commercial, Mac OS X)
//     http://www.n4te.com/hiero/hiero.jnlp (Free, Java)
//     http://slick.cokeandcode.com/demos/hiero.jnlp (Free, Java)
//     http://www.angelcode.com/products/bmfont/ (Free, Windows only)
//
//------------------------------------------------------------------

Atlas5::Atlas5()
{
	CCLabelBMFont *label = CCLabelBMFont::labelWithString("abcdefg", "fonts/bitmapFontTest4.fnt");
	addChild(label);

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

	label->setPosition( ccp(s.width/2, s.height/2) );
	label->setAnchorPoint( ccp(0.5f, 0.5f) );
}

std::string Atlas5::title()
{
	return "CCLabelBMFont";
}

std::string Atlas5::subtitle()
{
	return "Testing padding";
}
//------------------------------------------------------------------
//
// Atlas6
//
// Use any of these editors to generate BMFonts:
//     http://glyphdesigner.71squared.com/ (Commercial, Mac OS X)
//     http://www.n4te.com/hiero/hiero.jnlp (Free, Java)
//     http://slick.cokeandcode.com/demos/hiero.jnlp (Free, Java)
//     http://www.angelcode.com/products/bmfont/ (Free, Windows only)
//
//------------------------------------------------------------------

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

	CCLabelBMFont* label = NULL;
	//中国
	label = CCLabelBMFont::labelWithString("中国", "fonts/bitmapFontChinese.fnt",
		CCTextAlignmentRight, 200);
	addChild(label);
	label->setPosition( ccp(s.width / 2.0f, s.height / 2.0f + 50) );
	label->setAnchorPoint( ccp(1.0f, 0.5f) ) ;

	label = CCLabelBMFont::labelWithString("fafefifofu", "fonts/bitmapFontTest5.fnt");
	addChild(label);
	label->setPosition( ccp(s.width/2, s.height/2) );
	label->setAnchorPoint( ccp(0.5f, 0.5f) );

	label = CCLabelBMFont::labelWithString("aeiou", "fonts/bitmapFontTest5.fnt");
	addChild(label);
	label->setPosition( ccp(s.width/2, s.height/2-50) );
	label->setAnchorPoint( ccp(0.5f, 0.5f) );
}

std::string Atlas6::title()
{
	return "CCLabelBMFont";
}

std::string Atlas6::subtitle()
{
	return "Rendering should be OK. Testing offset";
}

//------------------------------------------------------------------
//
// AtlasBitmapColor
//
// Use any of these editors to generate BMFonts:
//     http://glyphdesigner.71squared.com/ (Commercial, Mac OS X)
//     http://www.n4te.com/hiero/hiero.jnlp (Free, Java)
//     http://slick.cokeandcode.com/demos/hiero.jnlp (Free, Java)
//     http://www.angelcode.com/products/bmfont/ (Free, Windows only)
//
//------------------------------------------------------------------
AtlasBitmapColor::AtlasBitmapColor()
{
	CCSize s = CCDirector::sharedDirector()->getWinSize();

	CCLabelBMFont* label = NULL;
	label = CCLabelBMFont::labelWithString("Blue", "fonts/bitmapFontTest5.fnt");
	label->setColor( ccBLUE );
	addChild(label);
	label->setPosition( ccp(s.width/2, s.height/4) );
	label->setAnchorPoint( ccp(0.5f, 0.5f) );

	label = CCLabelBMFont::labelWithString("Red", "fonts/bitmapFontTest5.fnt");
	addChild(label);
	label->setPosition( ccp(s.width/2, 2*s.height/4) );
	label->setAnchorPoint( ccp(0.5f, 0.5f) );
	label->setColor( ccRED );

	label = CCLabelBMFont::labelWithString("G", "fonts/bitmapFontTest5.fnt");
	addChild(label);
	label->setPosition( ccp(s.width/2, 3*s.height/4) );
	label->setAnchorPoint( ccp(0.5f, 0.5f) );
	label->setColor( ccGREEN );
	label->setString("Green");
}

std::string AtlasBitmapColor::title()
{
	return "CCLabelBMFont";
}

std::string AtlasBitmapColor::subtitle()
{
	return "Testing color";
}

//------------------------------------------------------------------
//
// AtlasFastBitmap
//
// Use any of these editors to generate BMFonts:
//     http://glyphdesigner.71squared.com/ (Commercial, Mac OS X)
//     http://www.n4te.com/hiero/hiero.jnlp (Free, Java)
//     http://slick.cokeandcode.com/demos/hiero.jnlp (Free, Java)
//     http://www.angelcode.com/products/bmfont/ (Free, Windows only)
//
//------------------------------------------------------------------

AtlasFastBitmap::AtlasFastBitmap()
{
		// Upper Label
		for( int i=0 ; i < 100;i ++ )
		{
            char str[6] = {0};
            sprintf(str, "-%d-", i);
			CCLabelBMFont* label = CCLabelBMFont::labelWithString(str, "fonts/bitmapFontTest.fnt");
			addChild(label);

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

			CCPoint p = ccp( CCRANDOM_0_1() * s.width, CCRANDOM_0_1() * s.height);
			label->setPosition( p );
			label->setAnchorPoint(ccp(0.5f, 0.5f));
		}
}

std::string AtlasFastBitmap::title()
{
	return "CCLabelBMFont";
}

std::string AtlasFastBitmap::subtitle()
{
	return "Creating several CCLabelBMFont with the same .fnt file should be fast";
}

//------------------------------------------------------------------
//
// BitmapFontMultiLine
//
// Use any of these editors to generate BMFonts:
//     http://glyphdesigner.71squared.com/ (Commercial, Mac OS X)
//     http://www.n4te.com/hiero/hiero.jnlp (Free, Java)
//     http://slick.cokeandcode.com/demos/hiero.jnlp (Free, Java)
//     http://www.angelcode.com/products/bmfont/ (Free, Windows only)
//
//------------------------------------------------------------------
BitmapFontMultiLine::BitmapFontMultiLine()
{
    CCSize s;

    // Left
    CCLabelBMFont *label1 = CCLabelBMFont::labelWithString(" Multi line\nLeft", "fonts/bitmapFontTest3.fnt");
    label1->setAnchorPoint(ccp(0,0));
    addChild(label1, 0, kTagBitmapAtlas1);

    s = label1->getContentSize();
    CCLOG("content size: %.2fx%.2f", s.width, s.height);

    // Center
    CCLabelBMFont *label2 = CCLabelBMFont::labelWithString("Multi line\nCenter", "fonts/bitmapFontTest3.fnt");
    label2->setAnchorPoint(ccp(0.5f, 0.5f));
    addChild(label2, 0, kTagBitmapAtlas2);

    s= label2->getContentSize();
    CCLOG("content size: %.2fx%.2f", s.width, s.height);

    // right
    CCLabelBMFont *label3 = CCLabelBMFont::labelWithString("Multi line\nRight\nThree lines Three", "fonts/bitmapFontTest3.fnt");
    label3->setAnchorPoint(ccp(1, 1));
    addChild(label3, 0, kTagBitmapAtlas3);

    s = label3->getContentSize();
    CCLOG("content size: %.2fx%.2f", s.width, s.height);

    s = CCDirector::sharedDirector()->getWinSize();
    label1->setPosition(ccp( 0,0));
    label2->setPosition(ccp( s.width/2, s.height/2));
    label3->setPosition(ccp( s.width, s.height));
}

std::string BitmapFontMultiLine::title()
{
    return "CCLabelBMFont";
}

std::string BitmapFontMultiLine::subtitle()
{
    return "Multiline + anchor point";
}

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

    // CCLabelBMFont
    CCLabelBMFont *label1 = CCLabelBMFont::labelWithString("", "fonts/bitmapFontTest3.fnt");
    addChild(label1, 0, kTagBitmapAtlas1);
    label1->setPosition(ccp(s.width/2, s.height-100));

    // CCLabelTTF
    CCLabelTTF* label2 = CCLabelTTF::labelWithString("", "Arial", 24);
    addChild(label2, 0, kTagBitmapAtlas2);
    label2->setPosition(ccp(s.width/2, s.height/2));

    // CCLabelAtlas
    CCLabelAtlas *label3 = CCLabelAtlas::labelWithString("", "fonts/tuffy_bold_italic-charmap.png", 48, 64, ' ');
    addChild(label3, 0, kTagBitmapAtlas3);
    label3->setPosition(ccp(s.width/2, 0+100));

    schedule(schedule_selector(LabelsEmpty::updateStrings), 1.0f);

    setEmpty = false;
}

void LabelsEmpty::updateStrings(ccTime dt)
{
    CCLabelBMFont* label1 = (CCLabelBMFont*) getChildByTag(kTagBitmapAtlas1);
    CCLabelTTF* label2 = (CCLabelTTF*) getChildByTag(kTagBitmapAtlas2);
    CCLabelAtlas* label3 = (CCLabelAtlas*) getChildByTag(kTagBitmapAtlas3);

    if( ! setEmpty )
    {
        label1->setString("not empty");
        label2->setString("not empty");
        label3->setString("hi");

        setEmpty = true;
    }
    else
    {
        label1->setString("");
        label2->setString("");
        label3->setString("");

        setEmpty = false;
    }
}

std::string LabelsEmpty::title()
{
    return "Testing empty labels";
}

std::string LabelsEmpty::subtitle()
{
    return "3 empty labels: LabelAtlas, LabelTTF and LabelBMFont";
}

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

    // CCLabelBMFont
    CCLabelBMFont *label1 = CCLabelBMFont::labelWithString("TESTING RETINA DISPLAY", "fonts/konqa32.fnt");
    addChild(label1);
    label1->setPosition(ccp(s.width/2, s.height/2));
}

std::string LabelBMFontHD::title()
{
    return "Testing Retina Display BMFont";
}

std::string LabelBMFontHD::subtitle()
{
    return "loading arista16 or arista16-hd";
}

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

    // CCLabelBMFont
    CCLabelAtlas *label1 = CCLabelAtlas::labelWithString("TESTING RETINA DISPLAY", "fonts/larabie-16.png", 10, 20, 'A');
    label1->setAnchorPoint(ccp(0.5f, 0.5f));

    addChild(label1);
    label1->setPosition(ccp(s.width/2, s.height/2));
}

std::string LabelAtlasHD::title()
{
    return "LabelAtlas with Retina Display";
}

std::string LabelAtlasHD::subtitle()
{
    return "loading larabie-16 / larabie-16-hd";
}

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

    CCLayerColor *layer = CCLayerColor::layerWithColor(ccc4f(128,128,128,255));
    addChild(layer, -10);

    // CCLabelBMFont
    CCLabelBMFont *label1 = CCLabelBMFont::labelWithString("Testing Glyph Designer", "fonts/futura-48.fnt");
    addChild(label1);
    label1->setPosition(ccp(s.width/2, s.height/2));
}

std::string LabelGlyphDesigner::title()
{
    return "Testing Glyph Designer";
}

std::string LabelGlyphDesigner::subtitle()
{
    return "You should see a font with shawdows and outline";
}

void AtlasTestScene::runThisTest()
{
    CCLayer* pLayer = nextAtlasAction();
    addChild(pLayer);

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

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

	// CCLabelBMFont
	CCLabelTTF *left = CCLabelTTF::labelWithString("align left", CCSizeMake(s.width, 50), CCTextAlignmentLeft, "Marker Felt", 32);
	CCLabelTTF *center = CCLabelTTF::labelWithString("align center", CCSizeMake(s.width, 50), CCTextAlignmentCenter, "Marker Felt", 32);
	CCLabelTTF *right = CCLabelTTF::labelWithString("align right", CCSizeMake(s.width, 50), CCTextAlignmentRight, "Marker Felt", 32);

	left->setPosition(ccp(s.width / 2, 200));
	center->setPosition(ccp(s.width / 2, 150));
	right->setPosition(ccp(s.width / 2, 100));

	addChild(left);
	addChild(center);
	addChild(right);
}

string LabelTTFTest::title()
{
	return "Testing CCLabelTTF";
}

string LabelTTFTest::subtitle()
{
	return "You should see 3 labels aligned left, center and right";
}

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

	// CCLabelBMFont
	CCLabelTTF *center = CCLabelTTF::labelWithString("word wrap \"testing\" (bla0) bla1 'bla2' [bla3] (bla4) {bla5} {bla6} [bla7] (bla8) [bla9] 'bla0' \"bla1\"",
		CCSizeMake(s.width / 2, 200), CCTextAlignmentCenter, "MarkerFelt.ttc", 32);
	center->setPosition(ccp(s.width / 2, 150));

	addChild(center);
}

string LabelTTFMultiline::title()
{
	return "Testing CCLabelTTF Word Wrap";
}

string LabelTTFMultiline::subtitle()
{
	return "Word wrap using CCLabelTTF";
}

LabelTTFChinese::LabelTTFChinese()
{
	CCSize size = CCDirector::sharedDirector()->getWinSize();
	CCLabelTTF *pLable = CCLabelTTF::labelWithString("中国", "Marker Felt", 30);
	pLable->setPosition(ccp(size.width / 2, size.height /2));
	this->addChild(pLable);
}

string LabelTTFChinese::title()
{
	return "Testing CCLabelTTF with Chinese character";
}

LabelBMFontChinese::LabelBMFontChinese()
{
    CCSize size = CCDirector::sharedDirector()->getWinSize();
    CCLabelBMFont* pLable = CCLabelBMFont::labelWithString("abc中国中国efghi中国中国JKLMn中国", "fonts/bitmapFontChinese.fnt", CCTextAlignmentRight, 300);
    pLable->setLineBreakWithoutSpace(true);
	pLable->setPosition(ccp(size.width / 2, size.height /2));
    this->addChild(pLable);
}

string LabelBMFontChinese::title()
{
    return "Testing CCLabelBMFont with Chinese character";
}


code:
#ifndef _ATLAS_TEST_H_
#define _ATLAS_TEST_H_

#include "../testBasic.h"

class AtlasDemo : public CCLayer
{
protected:

public:
	AtlasDemo(void);
	~AtlasDemo(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 Atlas1 : public AtlasDemo
{
	CCTextureAtlas*		m_textureAtlas;
public:
	Atlas1();
	~Atlas1();
	virtual std::string title();
	virtual std::string subtitle();
	virtual void draw();
};

class LabelAtlasTest : public AtlasDemo
{
	ccTime		m_time;
public:
	LabelAtlasTest();

	virtual void step(ccTime dt);

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

class LabelAtlasColorTest : public AtlasDemo
{
	ccTime		m_time;
public:
	LabelAtlasColorTest();
	virtual void step(ccTime dt);
	virtual std::string title();
	virtual std::string subtitle();
};

class Atlas3 : public AtlasDemo
{
	ccTime		m_time;
public:
	Atlas3();

	virtual void step(ccTime dt);

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

class Atlas4 : public AtlasDemo
{
	ccTime		m_time;
public:
	Atlas4();
	virtual void step(ccTime dt);
	virtual void draw();

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

class Atlas5 : public AtlasDemo
{
public:
	Atlas5();
	virtual std::string title();
	virtual std::string subtitle();
};

class Atlas6 : public AtlasDemo
{
public:
	Atlas6();
	virtual std::string title();
	virtual std::string subtitle();
};

class AtlasBitmapColor : public AtlasDemo
{
public:
	AtlasBitmapColor();
	virtual std::string title();

	virtual std::string subtitle();
};

class AtlasFastBitmap : public AtlasDemo
{
public:
	AtlasFastBitmap();
	virtual std::string title();
	virtual std::string subtitle();
};

class BitmapFontMultiLine : public AtlasDemo
{
public:
    BitmapFontMultiLine();
    virtual std::string title();
    virtual std::string subtitle();
};

class LabelsEmpty : public AtlasDemo
{
public:
    LabelsEmpty();
    void updateStrings(ccTime dt);
    virtual std::string title();
    virtual std::string subtitle();

private:
    bool setEmpty;
};

class LabelBMFontHD : public AtlasDemo
{
public:
    LabelBMFontHD();
    virtual std::string title();
    virtual std::string subtitle();
};

class LabelAtlasHD : public AtlasDemo
{
public:
    LabelAtlasHD();
    virtual std::string title();
    virtual std::string subtitle();
};

class LabelGlyphDesigner : public AtlasDemo
{
public:
    LabelGlyphDesigner();
    virtual std::string title();
    virtual std::string subtitle();
};

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

class LabelTTFTest : public AtlasDemo
{
public:
	LabelTTFTest();
	virtual std::string title();
	virtual std::string subtitle();
};

class LabelTTFMultiline : public AtlasDemo
{
public:
	LabelTTFMultiline();
	virtual std::string title();
	virtual std::string subtitle();
};

class LabelTTFChinese : public AtlasDemo
{
public:
	LabelTTFChinese();
	virtual std::string title();
};

class LabelBMFontChinese : public AtlasDemo
{
public:
    LabelBMFontChinese();
    virtual std::string title();
};

// we don't support linebreak mode

#endif

license: mit


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

enum
{
	kTagLayer = 1,
};

CCLayer* nextTestAction();
CCLayer* backTestAction();
CCLayer* restartTestAction();

static int sceneIdx = -1;

#define MAX_LAYER	4

CCLayer* createTestLayer(int nIndex)
{
	switch(nIndex)
	{
		case 0: return new LayerTest1();
		case 1: return new LayerTest2();
		case 2: return new LayerTestBlend();
        case 3: return new LayerGradient();
	}

	return NULL;
}

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

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

	return pLayer;
}

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

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

	return pLayer;
}

CCLayer* restartTestAction()
{
	CCLayer* pLayer = createTestLayer(sceneIdx);
	pLayer->autorelease();

	return pLayer;
}

//------------------------------------------------------------------
//
// LayerTest
//
//------------------------------------------------------------------

LayerTest::LayerTest(void)
{
}

LayerTest::~LayerTest(void)
{
}

string LayerTest::subtitle()
{
	return "";
}

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

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

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

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

	string subtitle_ = subtitle();
	if (subtitle_.size() > 0)
	{
		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(s_pPathB1, s_pPathB2, this, menu_selector(LayerTest::backCallback) );
	CCMenuItemImage *item2 = CCMenuItemImage::itemFromNormalImage(s_pPathR1, s_pPathR2, this, menu_selector(LayerTest::restartCallback) );
	CCMenuItemImage *item3 = CCMenuItemImage::itemFromNormalImage(s_pPathF1, s_pPathF2, this, menu_selector(LayerTest::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 LayerTest::restartCallback(CCObject* pSender)
{
	CCScene* s = new LayerTestScene();
	s->addChild(restartTestAction());

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

void LayerTest::nextCallback(CCObject* pSender)
{
	CCScene* s = new LayerTestScene();
	s->addChild( nextTestAction() );
	CCDirector::sharedDirector()->replaceScene(s);
    s->release();
}

void LayerTest::backCallback(CCObject* pSender)
{
	CCScene* s = new LayerTestScene();
	s->addChild( backTestAction() );
	CCDirector::sharedDirector()->replaceScene(s);
    s->release();
}

//------------------------------------------------------------------
//
// LayerTest1
//
//------------------------------------------------------------------
void LayerTest1::onEnter()
{
	LayerTest::onEnter();

	setIsTouchEnabled(true);

	CCSize s = CCDirector::sharedDirector()->getWinSize();
	CCLayerColor* layer = CCLayerColor::layerWithColorWidthHeight( ccc4f(0xFF, 0x00, 0x00, 0x80), 200, 200);

	layer->setIsRelativeAnchorPoint(true);
	layer->setPosition( CCPointMake(s.width/2, s.height/2) );
	addChild(layer, 1, kTagLayer);
}

void LayerTest1::registerWithTouchDispatcher()
{
    CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, kCCMenuTouchPriority + 1, true);
}

void LayerTest1::updateSize(CCTouch*touch)
{
	CCPoint touchLocation = touch->locationInView();
	touchLocation = CCDirector::sharedDirector()->convertToGL( touchLocation );

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

	CCSize newSize = CCSizeMake( fabs(touchLocation.x - s.width/2)*2, fabs(touchLocation.y - s.height/2)*2);

	CCLayerColor* l = (CCLayerColor*) getChildByTag(kTagLayer);

	l->setContentSize( newSize );
}

bool LayerTest1::ccTouchBegan(CCTouch* touch, CCEvent* event)
{
	updateSize(touch);

	return true;
}

void LayerTest1::ccTouchMoved(CCTouch* touch, CCEvent* event)
{
	updateSize(touch);
}

void LayerTest1::ccTouchEnded(CCTouch* touch, CCEvent* event)
{
	updateSize(touch);
}

std::string LayerTest1::title()
{
	return "ColorLayer resize (tap & move)";
}

//------------------------------------------------------------------
//
// LayerTest2
//
//------------------------------------------------------------------
void LayerTest2::onEnter()
{
	LayerTest::onEnter();

	CCSize s = CCDirector::sharedDirector()->getWinSize();
	CCLayerColor* layer1 = CCLayerColor::layerWithColorWidthHeight( ccc4f(255, 255, 0, 80), 100, 300);
	layer1->setPosition(CCPointMake(s.width/3, s.height/2));
	layer1->setIsRelativeAnchorPoint(true);
	addChild(layer1, 1);

	CCLayerColor* layer2 = CCLayerColor::layerWithColorWidthHeight( ccc4f(0, 0, 255, 255), 100, 300);
	layer2->setPosition(CCPointMake((s.width/3)*2, s.height/2));
	layer2->setIsRelativeAnchorPoint(true);
	addChild(layer2, 1);

	CCActionInterval* actionTint = CCTintBy::actionWithDuration(2, -255, -127, 0);
	CCActionInterval* actionTintBack = actionTint->reverse();
	CCActionInterval* seq1 = (CCActionInterval*)CCSequence::actions( actionTint, actionTintBack, NULL);
	layer1->runAction(seq1);

	CCActionInterval* actionFade = CCFadeOut::actionWithDuration(2.0f);
	CCActionInterval* actionFadeBack = actionFade->reverse();
	CCActionInterval* seq2 = (CCActionInterval*)CCSequence::actions(actionFade, actionFadeBack, NULL);
	layer2->runAction(seq2);
}

std::string LayerTest2::title()
{
	return "ColorLayer: fade and tint";
}

//------------------------------------------------------------------
//
// LayerTestBlend
//
//------------------------------------------------------------------

LayerTestBlend::LayerTestBlend()
{
	CCSize s = CCDirector::sharedDirector()->getWinSize();
	CCLayerColor* layer1 = CCLayerColor::layerWithColor( ccc4f(255, 255, 255, 80) );

	CCSprite* sister1 = CCSprite::spriteWithFile(s_pPathSister1);
	CCSprite* sister2 = CCSprite::spriteWithFile(s_pPathSister2);

	addChild(sister1);
	addChild(sister2);
	addChild(layer1, 100, kTagLayer);

	sister1->setPosition( CCPointMake( 160, s.height/2) );
	sister2->setPosition( CCPointMake( 320, s.height/2) );

	schedule( schedule_selector(LayerTestBlend::newBlend), 1.0f);
}

void LayerTestBlend::newBlend(ccTime dt)
{
 	CCLayerColor *layer = (CCLayerColor*)getChildByTag(kTagLayer);

    GLenum src;
    GLenum dst;

	if( layer->getBlendFunc().dst == GL_ZERO )
    {
        src = CC_BLEND_SRC;
        dst = CC_BLEND_DST;
    }
	else
    {
        src = GL_ONE_MINUS_DST_COLOR;
        dst = GL_ZERO;
    }

    ccBlendFunc bf = {src, dst};
    layer->setBlendFunc( bf );
}

std::string LayerTestBlend::title()
{
	return "ColorLayer: blend";
}

//------------------------------------------------------------------
//
// LayerGradient
//
//------------------------------------------------------------------
LayerGradient::LayerGradient()
{
    CCLayerGradient* layer1 = CCLayerGradient::layerWithColor(ccc4f(255,0,0,255), ccc4f(0,255,0,255), ccp(0.9f, 0.9f));
    addChild(layer1, 0, kTagLayer);

    setIsTouchEnabled(true);

	CCLabelTTF *label1 = CCLabelTTF::labelWithString("Compressed Interpolation: Enabled", "Marker Felt", 26);
	CCLabelTTF *label2 = CCLabelTTF::labelWithString("Compressed Interpolation: Disabled", "Marker Felt", 26);
	CCMenuItemLabel *item1 = CCMenuItemLabel::itemWithLabel(label1);
	CCMenuItemLabel *item2 = CCMenuItemLabel::itemWithLabel(label2);
	CCMenuItemToggle *item = CCMenuItemToggle::itemWithTarget(this, menu_selector(LayerGradient::toggleItem), item1, item2, NULL);

	CCMenu *menu = CCMenu::menuWithItems(item, NULL);
	addChild(menu);
	CCSize s = CCDirector::sharedDirector()->getWinSize();
	menu->setPosition(ccp(s.width / 2, 100));
}

void LayerGradient::toggleItem(CCObject *sender)
{
	CCLayerGradient *gradient = (CCLayerGradient*)getChildByTag(kTagLayer);
	gradient->setIsCompressedInterpolation(! gradient->getIsCompressedInterpolation());
}

void LayerGradient::ccTouchesMoved(CCSet * touches, CCEvent *event)
{
    CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCSetIterator it = touches->begin();
    CCTouch* touch = (CCTouch*)(*it);
    CCPoint start = touch->locationInView();
    start = CCDirector::sharedDirector()->convertToGL(start);

    CCPoint diff = ccpSub( ccp(s.width/2,s.height/2), start);
    diff = ccpNormalize(diff);

    CCLayerGradient *gradient = (CCLayerGradient*) getChildByTag(1);
    gradient->setVector(diff);
}

std::string LayerGradient::title()
{
    return "LayerGradient";
}

string LayerGradient::subtitle()
{
	return "Touch the screen and move your finger";
}

void LayerTestScene::runThisTest()
{
    CCLayer* pLayer = nextTestAction();
    addChild(pLayer);

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


code:
#ifndef _LAYER_TEST_H_
#define _LAYER_TEST_H_

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

class LayerTest : public CCLayer
{
protected:
	std::string	m_strTitle;

public:
	LayerTest(void);
	~LayerTest(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 LayerTest1 : public LayerTest
{
public:
	virtual void onEnter();
	virtual std::string title();

	void registerWithTouchDispatcher();
	void updateSize(CCTouch*touch);

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

class LayerTest2 : public LayerTest
{
public:
	virtual void onEnter();
	virtual std::string title();
};

class LayerTestBlend : public LayerTest
{
public:
	LayerTestBlend();
	void newBlend(ccTime dt);
	virtual std::string title();
};

class LayerGradient : public LayerTest
{
public:
    LayerGradient();
    virtual void ccTouchesMoved(CCSet * touches, CCEvent *event);
    virtual std::string title();
	virtual std::string subtitle();
	void toggleItem(cocos2d::CCObject *sender);
};

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

#endif


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

enum {
	kTagMenu = 1,
	kTagMenu0 = 0,
	kTagMenu1 = 1,
};

#define MID_CALLBACK	1000
#define MID_CALLBACK2	1001
#define MID_DISABLED	1002
#define MID_ENABLE		1003
#define MID_CONFIG		1004
#define MID_QUIT		1005
#define MID_OPACITY		1006
#define MID_ALIGN		1007
#define MID_CALLBACK3	1008
#define MID_BACKCALLBACK 1009

//------------------------------------------------------------------
//
// MenuLayer1
//
//------------------------------------------------------------------
MenuLayer1::MenuLayer1()
{
	CCMenuItemFont::setFontSize( 30 );
	CCMenuItemFont::setFontName("Courier New");

    setIsTouchEnabled(true);
	// Font Item

	CCSprite* spriteNormal = CCSprite::spriteWithFile(s_MenuItem, CCRectMake(0,23*2,115,23));
	CCSprite* spriteSelected = CCSprite::spriteWithFile(s_MenuItem, CCRectMake(0,23*1,115,23));
	CCSprite* spriteDisabled = CCSprite::spriteWithFile(s_MenuItem, CCRectMake(0,23*0,115,23));
	//dynamic_cast<CCNode*>(mgr)->addChild(spriteNormal);
	//dynamic_cast<CCNode*>(mgr)->addChild(spriteSelected);
	//dynamic_cast<CCNode*>(mgr)->addChild(spriteDisabled);

	CCMenuItemSprite* item1 = CCMenuItemSprite::itemFromNormalSprite(spriteNormal, spriteSelected, spriteDisabled, this, menu_selector(MenuLayer1::menuCallback) );

	// Image Item
	CCMenuItem* item2 = CCMenuItemImage::itemFromNormalImage(s_SendScore, s_PressSendScore, this, menu_selector(MenuLayer1::menuCallback2) );

	// Label Item (LabelAtlas)
	CCLabelAtlas* labelAtlas = CCLabelAtlas::labelWithString("0123456789", "fonts/fps_images.png", 16, 24, '.');
	CCMenuItemLabel* item3 = CCMenuItemLabel::itemWithLabel(labelAtlas, this, menu_selector(MenuLayer1::menuCallbackDisabled) );
	item3->setDisabledColor( ccc3(32,32,64) );
	item3->setColor( ccc3(200,200,255) );

	// Font Item
	CCMenuItemFont *item4 = CCMenuItemFont::itemFromString("I toggle enable items", this, menu_selector(MenuLayer1::menuCallbackEnable) );

	item4->setFontSizeObj(20);
	item4->setFontName("Marker Felt");

	// Label Item (CCLabelBMFont)
	CCLabelBMFont* label = CCLabelBMFont::labelWithString("configuration", "fonts/bitmapFontTest3.fnt");
	CCMenuItemLabel* item5 = CCMenuItemLabel::itemWithLabel(label, this, menu_selector(MenuLayer1::menuCallbackConfig));

	// Testing issue #500
	item5->setScale( 0.8f );

	// Font Item
	CCMenuItemFont* item6 = CCMenuItemFont::itemFromString("Quit", this, menu_selector(MenuLayer1::onQuit));

	CCActionInterval* color_action = CCTintBy::actionWithDuration(0.5f, 0, -255, -255);
	CCActionInterval* color_back = color_action->reverse();
	CCFiniteTimeAction* seq = CCSequence::actions(color_action, color_back, NULL);
	item6->runAction(CCRepeatForever::actionWithAction((CCActionInterval*)seq));

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

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

	int i=0;
	CCNode* child;
	CCArray * pArray = menu->getChildren();
    CCObject* pObject = NULL;
    CCARRAY_FOREACH(pArray, pObject)
	{
		if(pObject == NULL)
			break;

		child = (CCNode*)pObject;

		CCPoint dstPoint = child->getPosition();
		int offset = (int) (s.width/2 + 50);
		if( i % 2 == 0)
			offset = -offset;

		child->setPosition( CCPointMake( dstPoint.x + offset, dstPoint.y) );
		child->runAction(
							CCEaseElasticOut::actionWithAction(
																CCMoveBy::actionWithDuration(2, CCPointMake(dstPoint.x - offset,0)), 0.35f
															)
						);
		i++;
	}

	m_disabledItem = item3; item3->retain();
	m_disabledItem->setIsEnabled( false );

	addChild(menu);

}

void MenuLayer1::registerWithTouchDispatcher()
{
    CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, kCCMenuTouchPriority+1, true);
}

bool MenuLayer1::ccTouchBegan(CCTouch *touch, CCEvent * pEvent)
{
    return true;
}

void MenuLayer1::ccTouchEnded(CCTouch *touch, CCEvent * pEvent)
{
}

void MenuLayer1::ccTouchCancelled(CCTouch *touch, CCEvent * pEvent)
{
}

void MenuLayer1::ccTouchMoved(CCTouch *touch, CCEvent * pEvent)
{
}

MenuLayer1::~MenuLayer1()
{
	m_disabledItem->release();
}

void MenuLayer1::menuCallback(CCObject* sender)
{
	((CCLayerMultiplex*)m_pParent)->switchTo(1);
}

void MenuLayer1::menuCallbackConfig(CCObject* sender)
{
	((CCLayerMultiplex*)m_pParent)->switchTo(3);
}

void MenuLayer1::allowTouches(ccTime dt)
{
    CCTouchDispatcher::sharedDispatcher()->setPriority(kCCMenuTouchPriority+1, this);
    unscheduleAllSelectors();
    CCLog("TOUCHES ALLOWED AGAIN");
}

void MenuLayer1::menuCallbackDisabled(CCObject* sender)
{
    // hijack all touch events for 5 seconds
    CCTouchDispatcher::sharedDispatcher()->setPriority(kCCMenuTouchPriority-1, this);
    schedule(schedule_selector(MenuLayer1::allowTouches), 5.0f);
    CCLog("TOUCHES DISABLED FOR 5 SECONDS");
}

void MenuLayer1::menuCallbackEnable(CCObject* sender)
{
	m_disabledItem->setIsEnabled(! m_disabledItem->getIsEnabled() );
}

void MenuLayer1::menuCallback2(CCObject* sender)
{
	((CCLayerMultiplex*)m_pParent)->switchTo(2);
}

void MenuLayer1::onQuit(CCObject* sender)
{
	//[[Director sharedDirector] end];
	//getCocosApp()->exit();
}

//------------------------------------------------------------------
//
// MenuLayer2
//
//------------------------------------------------------------------
MenuLayer2::MenuLayer2()
{
	for( int i=0;i < 2;i++ )
	{
		CCMenuItemImage* item1 = CCMenuItemImage::itemFromNormalImage(s_PlayNormal, s_PlaySelect, this, menu_selector(MenuLayer2::menuCallback));
		CCMenuItemImage* item2 = CCMenuItemImage::itemFromNormalImage(s_HighNormal, s_HighSelect, this, menu_selector(MenuLayer2::menuCallbackOpacity) );
		CCMenuItemImage* item3 = CCMenuItemImage::itemFromNormalImage(s_AboutNormal, s_AboutSelect, this, menu_selector(MenuLayer2::menuCallbackAlign) );

		item1->setScaleX( 1.5f );
		item2->setScaleX( 0.5f );
		item3->setScaleX( 0.5f );

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

		menu->setTag( kTagMenu );

		addChild(menu, 0, 100+i);

		m_centeredMenu = menu->getPosition();
	}

	m_alignedH = true;
	alignMenusH();
}

MenuLayer2::~MenuLayer2()
{
}

void MenuLayer2::alignMenusH()
{
	for(int i=0;i<2;i++)
	{
		CCMenu *menu = (CCMenu*)getChildByTag(100+i);
		menu->setPosition( m_centeredMenu );
		if(i==0)
		{
			// TIP: if no padding, padding = 5
			menu->alignItemsHorizontally();
			CCPoint p = menu->getPosition();
			menu->setPosition( ccpAdd(p, CCPointMake(0,30)) );

		}
		else
		{
			// TIP: but padding is configurable
			menu->alignItemsHorizontallyWithPadding(40);
			CCPoint p = menu->getPosition();
			menu->setPosition( ccpSub(p, CCPointMake(0,30)) );
		}
	}
}

void MenuLayer2::alignMenusV()
{
	for(int i=0;i<2;i++)
	{
		CCMenu *menu = (CCMenu*)getChildByTag(100+i);
		menu->setPosition( m_centeredMenu );
		if(i==0)
		{
			// TIP: if no padding, padding = 5
			menu->alignItemsVertically();
			CCPoint p = menu->getPosition();
			menu->setPosition( ccpAdd(p, CCPointMake(100,0)) );
		}
		else
		{
			// TIP: but padding is configurable
			menu->alignItemsVerticallyWithPadding(40);
			CCPoint p = menu->getPosition();
			menu->setPosition( ccpSub(p, CCPointMake(100,0)) );
		}
	}
}

void MenuLayer2::menuCallback(CCObject* sender)
{
	((CCLayerMultiplex*)m_pParent)->switchTo(0);
}

void MenuLayer2::menuCallbackOpacity(CCObject* sender)
{
	CCMenu* menu = (CCMenu*)(((CCNode*)(sender))->getParent());
	GLubyte opacity = menu->getOpacity();
	if( opacity == 128 )
		menu->setOpacity(255);
	else
		menu->setOpacity(128);
}

void MenuLayer2::menuCallbackAlign(CCObject* sender)
{
	m_alignedH = ! m_alignedH;

	if( m_alignedH )
		alignMenusH();
	else
		alignMenusV();
}

//------------------------------------------------------------------
//
// MenuLayer3
//
//------------------------------------------------------------------
MenuLayer3::MenuLayer3()
{
	CCMenuItemFont::setFontName("Marker Felt");
	CCMenuItemFont::setFontSize(28);

	CCLabelBMFont* label = CCLabelBMFont::labelWithString("Enable AtlasItem", "fonts/bitmapFontTest3.fnt");
	CCMenuItemLabel* item1 = CCMenuItemLabel::itemWithLabel(label, this, menu_selector(MenuLayer3::menuCallback2) );
	CCMenuItemFont* item2 = CCMenuItemFont::itemFromString("--- Go Back ---", this, menu_selector(MenuLayer3::menuCallback) );

	CCSprite *spriteNormal   = CCSprite::spriteWithFile(s_MenuItem,  CCRectMake(0,23*2,115,23));
	CCSprite *spriteSelected = CCSprite::spriteWithFile(s_MenuItem,  CCRectMake(0,23*1,115,23));
	CCSprite *spriteDisabled = CCSprite::spriteWithFile(s_MenuItem,  CCRectMake(0,23*0,115,23));

	CCMenuItemSprite* item3 = CCMenuItemSprite::itemFromNormalSprite(spriteNormal, spriteSelected, spriteDisabled, this, menu_selector(MenuLayer3::menuCallback3));
	m_disabledItem = item3;  item3->retain();
	m_disabledItem->setIsEnabled( false );

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

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

	item1->setPosition( CCPointMake(s.width/2 - 150, s.height/2) );
	item2->setPosition( CCPointMake(s.width/2 - 200, s.height/2) );
	item3->setPosition( CCPointMake(s.width/2, s.height/2 - 100) );

	CCJumpBy* jump = CCJumpBy::actionWithDuration(3, CCPointMake(400,0), 50, 4);
	item2->runAction( CCRepeatForever::actionWithAction(
								(CCActionInterval*)(CCSequence::actions( jump, jump->reverse(), NULL))
								)
					);
	CCActionInterval* spin1 = CCRotateBy::actionWithDuration(3, 360);
	CCActionInterval* spin2 = (CCActionInterval*)(spin1->copy()->autorelease());
	CCActionInterval* spin3 = (CCActionInterval*)(spin1->copy()->autorelease());

	item1->runAction( CCRepeatForever::actionWithAction(spin1) );
	item2->runAction( CCRepeatForever::actionWithAction(spin2) );
	item3->runAction( CCRepeatForever::actionWithAction(spin3) );

	addChild( menu );
}

MenuLayer3::~MenuLayer3()
{
	m_disabledItem->release();
}

void MenuLayer3::menuCallback(CCObject* sender)
{
	((CCLayerMultiplex*)m_pParent)->switchTo(0);
}

void MenuLayer3::menuCallback2(CCObject* sender)
{
	//UXLOG("Label clicked. Toogling AtlasSprite");
	m_disabledItem->setIsEnabled( ! m_disabledItem->getIsEnabled() );
	m_disabledItem->stopAllActions();
}

void MenuLayer3::menuCallback3(CCObject* sender)
{
	//UXLOG("MenuItemSprite clicked");
}

//------------------------------------------------------------------
//
// MenuLayer4
//
//------------------------------------------------------------------
MenuLayer4::MenuLayer4()
{
	CCMenuItemFont::setFontName("American Typewriter");
	CCMenuItemFont::setFontSize(18);
	CCMenuItemFont*title1 = CCMenuItemFont::itemFromString("Sound");
    title1->setIsEnabled(false);
	CCMenuItemFont::setFontName( "Marker Felt" );
	CCMenuItemFont::setFontSize(34);
	CCMenuItemToggle* item1 = CCMenuItemToggle::itemWithTarget(	this,
																menu_selector(MenuLayer4::menuCallback),
																CCMenuItemFont::itemFromString( "On" ),
																CCMenuItemFont::itemFromString( "Off"),
																NULL );

	CCMenuItemFont::setFontName( "American Typewriter" );
	CCMenuItemFont::setFontSize(18);
	CCMenuItemFont* title2 = CCMenuItemFont::itemFromString( "Music" );
    title2->setIsEnabled(false);
	CCMenuItemFont::setFontName( "Marker Felt" );
	CCMenuItemFont::setFontSize(34);
	CCMenuItemToggle *item2 = CCMenuItemToggle::itemWithTarget(	this,
																menu_selector(MenuLayer4::menuCallback),
																CCMenuItemFont::itemFromString( "On" ),
																CCMenuItemFont::itemFromString( "Off"),
																NULL );

	CCMenuItemFont::setFontName( "American Typewriter" );
	CCMenuItemFont::setFontSize(18);
	CCMenuItemFont* title3 = CCMenuItemFont::itemFromString( "Quality" );
    title3->setIsEnabled( false );
	CCMenuItemFont::setFontName( "Marker Felt" );
	CCMenuItemFont::setFontSize(34);
	CCMenuItemToggle *item3 = CCMenuItemToggle::itemWithTarget(	this,
																menu_selector(MenuLayer4::menuCallback),
																CCMenuItemFont::itemFromString( "High" ),
																CCMenuItemFont::itemFromString( "Low" ),
																NULL );

	CCMenuItemFont::setFontName( "American Typewriter" );
	CCMenuItemFont::setFontSize(18);
	CCMenuItemFont* title4 = CCMenuItemFont::itemFromString( "Orientation" );
    title4->setIsEnabled(false);
	CCMenuItemFont::setFontName( "Marker Felt" );
	CCMenuItemFont::setFontSize(34);
	CCMenuItemToggle *item4 = CCMenuItemToggle::itemWithTarget( this,
																menu_selector(MenuLayer4::menuCallback),
																CCMenuItemFont::itemFromString( "Off" ),
																NULL );

	//UxArray* more_items = UxArray::arrayWithObjects(
	//												 CCMenuItemFont::itemFromString( "33%" ),
	//												 CCMenuItemFont::itemFromString( "66%" ),
	//												 CCMenuItemFont::itemFromString( "100%" ),
	//												 NULL );
	// TIP: you can manipulate the items like any other CCMutableArray
	item4->getSubItems()->addObject( CCMenuItemFont::itemFromString( "33%" ) );
	item4->getSubItems()->addObject( CCMenuItemFont::itemFromString( "66%" ) );
	item4->getSubItems()->addObject( CCMenuItemFont::itemFromString( "100%" ) );

    // you can change the one of the items by doing this
    item4->setSelectedIndex( 2 );

    CCMenuItemFont::setFontName( "Marker Felt" );
	CCMenuItemFont::setFontSize( 34 );

	CCLabelBMFont *label = CCLabelBMFont::labelWithString( "go back", "fonts/bitmapFontTest3.fnt" );
	CCMenuItemLabel* back = CCMenuItemLabel::itemWithLabel(label, this, menu_selector(MenuLayer4::backCallback) );

	CCMenu *menu = CCMenu::menuWithItems(
                  title1, title2,
                  item1, item2,
                  title3, title4,
                  item3, item4,
                  back, NULL ); // 9 items.

	menu->alignItemsInColumns(2, 2, 2, 2, 1, NULL);

	addChild( menu );
}

MenuLayer4::~MenuLayer4()
{
}

void MenuLayer4::menuCallback(CCObject* sender)
{
	//UXLOG("selected item: %x index:%d", dynamic_cast<CCMenuItemToggle*>(sender)->selectedItem(), dynamic_cast<CCMenuItemToggle*>(sender)->selectedIndex() );
}

void MenuLayer4::backCallback(CCObject* sender)
{
	((CCLayerMultiplex*)m_pParent)->switchTo(0);
}

void MenuTestScene::runThisTest()
{
    CCLayer* pLayer1 = new MenuLayer1();
    CCLayer* pLayer2 = new MenuLayer2();
    CCLayer* pLayer3 = new MenuLayer3();
    CCLayer* pLayer4 = new MenuLayer4();

    CCLayerMultiplex* layer = CCLayerMultiplex::layerWithLayers(pLayer1, pLayer2, pLayer3, pLayer4, NULL);
    addChild(layer, 0);

    pLayer1->release();
    pLayer2->release();
    pLayer3->release();
    pLayer4->release();

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


code:
#ifndef _MENU_TEST_H_
#define _MENU_TEST_H_

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

class MenuLayer1 : public CCLayer
{
protected:
	CCMenuItem*	m_disabledItem;

public:
	MenuLayer1(void);
	~MenuLayer1();

public:
    virtual void registerWithTouchDispatcher();
    virtual bool ccTouchBegan(CCTouch *touch, CCEvent * pEvent);
    virtual void ccTouchEnded(CCTouch *touch, CCEvent * pEvent);
    virtual void ccTouchCancelled(CCTouch *touch, CCEvent * pEvent);
    virtual void ccTouchMoved(CCTouch *touch, CCEvent * pEvent);

    void allowTouches(ccTime dt);
	void menuCallback(CCObject* pSender);
	void menuCallbackConfig(CCObject* pSender);
	void menuCallbackDisabled(CCObject* pSender);
	void menuCallbackEnable(CCObject* pSender);
	void menuCallback2(CCObject* pSender);
	void onQuit(CCObject* pSender);

	//CREATE_NODE(MenuLayer1);
};

class MenuLayer2 : public CCLayer
{
protected:
	CCPoint		m_centeredMenu;
	bool                m_alignedH;

	void alignMenusH();
	void alignMenusV();

public:
	MenuLayer2(void);
	~MenuLayer2();

public:
	void menuCallback(CCObject* pSender);
	void menuCallbackOpacity(CCObject* pSender);
	void menuCallbackAlign(CCObject* pSender);

	//CREATE_NODE(MenuLayer2);
};

class MenuLayer3 : public CCLayer
{
protected:
	CCMenuItem*	m_disabledItem;

public:
	MenuLayer3(void);
	~MenuLayer3();

public:
	void menuCallback(CCObject* pSender);
	void menuCallback2(CCObject* pSender);
	void menuCallback3(CCObject* pSender);

	//CREATE_NODE(MenuLayer3);
};

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

public:
	void menuCallback(CCObject* pSender);
	void backCallback(CCObject* pSender);

	//CREATE_NODE(MenuLayer4);
};

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

#endif


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

CCLayer* nextMotionAction();
CCLayer* backMotionAction();
CCLayer* restartMotionAction();

//------------------------------------------------------------------
//
// MotionStreakTest1
//
//------------------------------------------------------------------

void MotionStreakTest1::onEnter()
{
	MotionStreakTest::onEnter();

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

	// the root object just rotates around
	m_root = CCSprite::spriteWithFile(s_pPathR1);
	addChild(m_root, 1);
	m_root->setPosition( CCPointMake(s.width/2, s.height/2) );

	// the target object is offset from root, and the streak is moved to follow it
	m_target = CCSprite::spriteWithFile(s_pPathR1);
	m_root->addChild(m_target);
	m_target->setPosition( CCPointMake(100,0) );

	// create the streak object and add it to the scene
	m_streak = CCMotionStreak::streakWithFade(2, 3, s_streak, 32, 32, ccc4f(0,255,0,255) );
	addChild( m_streak );
	// schedule an update on each frame so we can syncronize the streak with the target
	schedule(schedule_selector(MotionStreakTest1::onUpdate));

	CCActionInterval* a1 = CCRotateBy::actionWithDuration(2, 360);

	CCAction* action1 = CCRepeatForever::actionWithAction(a1);
	CCActionInterval* motion = CCMoveBy::actionWithDuration(2, CCPointMake(100,0) );
	m_root->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)(CCSequence::actions(motion, motion->reverse(), NULL)) ) );
	m_root->runAction( action1 );
}

void MotionStreakTest1::onUpdate(ccTime delta)
{
	m_streak->setPosition( m_target->convertToWorldSpace(CCPointZero) );
}

std::string MotionStreakTest1::title()
{
	return "MotionStreak test 1";
}

//------------------------------------------------------------------
//
// MotionStreakTest2
//
//------------------------------------------------------------------

void MotionStreakTest2::onEnter()
{
	MotionStreakTest::onEnter();

	setIsTouchEnabled(true);

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

	// create the streak object and add it to the scene
	m_streak = CCMotionStreak::streakWithFade(3, 3, s_streak, 64, 32, ccc4f(255,255,255,255) );
	addChild( m_streak );

	m_streak->setPosition( CCPointMake(s.width/2, s.height/2) );
}

void MotionStreakTest2::ccTouchesMoved(CCSet* touches, CCEvent* event)
{
    CCSetIterator it = touches->begin();
    CCTouch* touch = (CCTouch*)(*it);

	CCPoint touchLocation = touch->locationInView();
	touchLocation = CCDirector::sharedDirector()->convertToGL( touchLocation );

	m_streak->setPosition( touchLocation );
}

std::string MotionStreakTest2::title()
{
	return "MotionStreak test";
}

//------------------------------------------------------------------
//
// MotionStreakTest
//
//------------------------------------------------------------------

// enum
// {
// 	IDC_NEXT = 100,
// 	IDC_BACK,
// 	IDC_RESTART
// };

static int sceneIdx = -1;

#define MAX_LAYER	2

CCLayer* createMotionLayer(int nIndex)
{
	switch(nIndex)
	{
		case 0: return new MotionStreakTest1();
		case 1: return new MotionStreakTest2();
	}

	return NULL;
}

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

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

	return pLayer;
}

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

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

	return pLayer;
}

CCLayer* restartMotionAction()
{
	CCLayer* pLayer = createMotionLayer(sceneIdx);
	pLayer->autorelease();

	return pLayer;
}

MotionStreakTest::MotionStreakTest(void)
{
}

MotionStreakTest::~MotionStreakTest(void)
{
}

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

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

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

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

	CCMenuItemImage *item1 = CCMenuItemImage::itemFromNormalImage(s_pPathB1, s_pPathB2, this, menu_selector(MotionStreakTest::backCallback) );
	CCMenuItemImage *item2 = CCMenuItemImage::itemFromNormalImage(s_pPathR1, s_pPathR2, this, menu_selector(MotionStreakTest::restartCallback) );
	CCMenuItemImage *item3 = CCMenuItemImage::itemFromNormalImage(s_pPathF1, s_pPathF2, this, menu_selector(MotionStreakTest::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 MotionStreakTest::restartCallback(CCObject* pSender)
{
	CCScene* s = new MotionStreakTestScene();//CCScene::node();
	s->addChild(restartMotionAction());

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

void MotionStreakTest::nextCallback(CCObject* pSender)
{
	CCScene* s = new MotionStreakTestScene();//CCScene::node();
	s->addChild( nextMotionAction() );
	CCDirector::sharedDirector()->replaceScene(s);
    s->release();
}

void MotionStreakTest::backCallback(CCObject* pSender)
{
	CCScene* s = new MotionStreakTestScene;//CCScene::node();
	s->addChild( backMotionAction() );
	CCDirector::sharedDirector()->replaceScene(s);
    s->release();
}

void MotionStreakTestScene::runThisTest()
{
    CCLayer* pLayer = nextMotionAction();
    addChild(pLayer);

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


code:
#ifndef _MOTION_STREAK_TEST_H_
#define _MOTION_STREAK_TEST_H_

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

//using namespace cocos2d;

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

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

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

class MotionStreakTest1 : public MotionStreakTest
{
protected:
	CCNode*		m_root;
	CCNode*		m_target;
	CCMotionStreak*		m_streak;

public:
	virtual void onEnter();
	void onUpdate(ccTime delta);
	virtual std::string title();
};

class MotionStreakTest2 : public MotionStreakTest
{
protected:
	CCNode*		m_root;
	CCNode*		m_target;
	CCMotionStreak*		m_streak;

public:
	virtual void onEnter();
	void ccTouchesMoved(CCSet* touches, CCEvent* event);
	virtual std::string title();
};

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

//CCLayer* nextAction();

#endif


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

enum
{
	kTagNode,
	kTagGrossini,
};

CCLayer* nextParallaxAction();
CCLayer* backParallaxAction();
CCLayer* restartParallaxAction();

//------------------------------------------------------------------
//
// Parallax1
//
//------------------------------------------------------------------

Parallax1::Parallax1()
{
	// Top Layer, a simple image
	CCSprite* cocosImage = CCSprite::spriteWithFile(s_Power);
	// scale the image (optional)
	cocosImage->setScale( 2.5f );
	// change the transform anchor point to 0,0 (optional)
	cocosImage->setAnchorPoint( ccp(0,0) );

	// Middle layer: a Tile map atlas
	CCTileMapAtlas *tilemap = CCTileMapAtlas::tileMapAtlasWithTileFile(s_TilesPng, s_LevelMapTga, 16, 16);
	tilemap->releaseMap();

	// change the transform anchor to 0,0 (optional)
	tilemap->setAnchorPoint( ccp(0, 0) );

	// Anti Aliased images
    tilemap->getTexture()->setAntiAliasTexParameters();

	// background layer: another image
	CCSprite* background = CCSprite::spriteWithFile(s_back);
	// scale the image (optional)
	background->setScale( 1.5f );
	// change the transform anchor point (optional)
	background->setAnchorPoint( ccp(0,0) );

	// create a void node, a parent node
	CCParallaxNode* voidNode = CCParallaxNode::node();

	// NOW add the 3 layers to the 'void' node

	// background image is moved at a ratio of 0.4x, 0.5y
	voidNode->addChild(background, -1, ccp(0.4f,0.5f), CCPointZero);

	// tiles are moved at a ratio of 2.2x, 1.0y
	voidNode->addChild(tilemap, 1, ccp(2.2f,1.0f), ccp(0,-200) );

	// top image is moved at a ratio of 3.0x, 2.5y
	voidNode->addChild(cocosImage, 2, ccp(3.0f,2.5f), ccp(200,800) );

	// now create some actions that will move the 'void' node
	// and the children of the 'void' node will move at different
	// speed, thus, simulation the 3D environment
	CCActionInterval* goUp = CCMoveBy::actionWithDuration(4, ccp(0,-500) );
	CCActionInterval* goDown = goUp->reverse();
	CCActionInterval* go = CCMoveBy::actionWithDuration(8, ccp(-1000,0) );
	CCActionInterval* goBack = go->reverse();
	CCFiniteTimeAction* seq = CCSequence::actions(goUp, go, goDown, goBack, NULL);
	voidNode->runAction( (CCRepeatForever::actionWithAction((CCActionInterval*) seq) ));

	addChild( voidNode );
}

std::string Parallax1::title()
{
	return "Parallax: parent and 3 children";
}

//------------------------------------------------------------------
//
// Parallax2
//
//------------------------------------------------------------------

Parallax2::Parallax2()
{
	setIsTouchEnabled( true );

	// Top Layer, a simple image
	CCSprite* cocosImage = CCSprite::spriteWithFile(s_Power);
	// scale the image (optional)
	cocosImage->setScale( 2.5f );
	// change the transform anchor point to 0,0 (optional)
	cocosImage->setAnchorPoint( ccp(0,0) );

	// Middle layer: a Tile map atlas
	CCTileMapAtlas* tilemap = CCTileMapAtlas::tileMapAtlasWithTileFile(s_TilesPng, s_LevelMapTga, 16, 16);
	tilemap->releaseMap();

	// change the transform anchor to 0,0 (optional)
	tilemap->setAnchorPoint( ccp(0, 0) );

    // Anti Aliased images
    tilemap->getTexture()->setAntiAliasTexParameters();

	// background layer: another image
	CCSprite* background = CCSprite::spriteWithFile(s_back);
	// scale the image (optional)
	background->setScale( 1.5f );
	// change the transform anchor point (optional)
	background->setAnchorPoint( ccp(0,0) );

	// create a void node, a parent node
	CCParallaxNode* voidNode = CCParallaxNode::node();

	// NOW add the 3 layers to the 'void' node

	// background image is moved at a ratio of 0.4x, 0.5y
	voidNode->addChild(background, -1, ccp(0.4f,0.5f), CCPointZero);

	// tiles are moved at a ratio of 1.0, 1.0y
	voidNode->addChild(tilemap, 1, ccp(1.0f,1.0f), ccp(0,-200) );

	// top image is moved at a ratio of 3.0x, 2.5y
	voidNode->addChild( cocosImage, 2, ccp(3.0f,2.5f), ccp(200,1000) );
	addChild(voidNode, 0, kTagNode);
}

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

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

void Parallax2::ccTouchEnded(CCTouch* touch, CCEvent* event)
{
}

void Parallax2::ccTouchCancelled(CCTouch* touch, CCEvent* event)
{
}

void Parallax2::ccTouchMoved(CCTouch* touch, CCEvent* event)
{
	CCPoint touchLocation = touch->locationInView();
	CCPoint prevLocation = touch->previousLocationInView();

	touchLocation = CCDirector::sharedDirector()->convertToGL( touchLocation );
	prevLocation = CCDirector::sharedDirector()->convertToGL( prevLocation );

	CCPoint diff = ccpSub(touchLocation,prevLocation);

	CCNode* node = getChildByTag(kTagNode);
	CCPoint currentPos = node->getPosition();
	node->setPosition( ccpAdd(currentPos, diff) );
}

std::string Parallax2::title()
{
	return "Parallax: drag screen";
}

//------------------------------------------------------------------
//
// ParallaxDemo
//
//------------------------------------------------------------------

static int sceneIdx = -1;

#define MAX_LAYER	2

CCLayer* createParallaxTestLayer(int nIndex)
{
	switch(nIndex)
	{
		case 0: return new Parallax1();
		case 1: return new Parallax2();
	}

	return NULL;
}

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

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

	return pLayer;
}

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

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

	return pLayer;
}

CCLayer* restartParallaxAction()
{
	CCLayer* pLayer = createParallaxTestLayer(sceneIdx);
	pLayer->autorelease();

	return pLayer;
}

ParallaxDemo::ParallaxDemo(void)
{
}

ParallaxDemo::~ParallaxDemo(void)
{
}

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

void ParallaxDemo::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) );

	CCMenuItemImage *item1 = CCMenuItemImage::itemFromNormalImage(s_pPathB1, s_pPathB2, this, menu_selector(ParallaxDemo::backCallback) );
	CCMenuItemImage *item2 = CCMenuItemImage::itemFromNormalImage(s_pPathR1, s_pPathR2, this, menu_selector(ParallaxDemo::restartCallback) );
	CCMenuItemImage *item3 = CCMenuItemImage::itemFromNormalImage(s_pPathF1, s_pPathF2, this, menu_selector(ParallaxDemo::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 ParallaxDemo::restartCallback(CCObject* pSender)
{
	CCScene* s = new ParallaxTestScene();
	s->addChild(restartParallaxAction());

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

void ParallaxDemo::nextCallback(CCObject* pSender)
{
	CCScene* s = new ParallaxTestScene();
	s->addChild( nextParallaxAction() );
	CCDirector::sharedDirector()->replaceScene(s);
    s->release();
}

void ParallaxDemo::backCallback(CCObject* pSender)
{
	CCScene* s = new ParallaxTestScene();
	s->addChild( backParallaxAction() );
	CCDirector::sharedDirector()->replaceScene(s);
    s->release();
}

void ParallaxTestScene::runThisTest()
{
    CCLayer* pLayer = nextParallaxAction();

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


code:
#ifndef _PARALLAX_TEST_H_
#define _PARALLAX_TEST_H_

#include "../testBasic.h"

class ParallaxDemo : public CCLayer
{
protected:
    CCTextureAtlas* m_atlas;

public:
	ParallaxDemo(void);
	~ParallaxDemo(void);

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

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

class Parallax1 : public ParallaxDemo
{
protected:
	CCNode*		m_root;
	CCNode*		m_target;
	CCMotionStreak*		m_streak;

public:
	Parallax1();
	virtual std::string title();
};

class Parallax2 : public ParallaxDemo
{
protected:
	CCNode*		m_root;
	CCNode*		m_target;
	CCMotionStreak*		m_streak;

public:
	Parallax2();

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

	virtual std::string title();
};

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

#endif