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

enum
{
	kTagTileMap = 1,
};

CCLayer* nextTileMapAction();
CCLayer* backTileMapAction();
CCLayer* restartTileMapAction();

//------------------------------------------------------------------
//
// TileMapTest
//
//------------------------------------------------------------------
TileMapTest::TileMapTest()
{
	CCTileMapAtlas* map = CCTileMapAtlas::tileMapAtlasWithTileFile(s_TilesPng,  s_LevelMapTga, 16, 16);
	// Convert it to "alias" (GL_LINEAR filtering)
	map->getTexture()->setAntiAliasTexParameters();

	CCSize s = map->getContentSize();
	////----UXLOG("ContentSize: %f, %f", s.width,s.height);

	// If you are not going to use the Map, you can free it now
	// NEW since v0.7
	map->releaseMap();

	addChild(map, 0, kTagTileMap);

	map->setAnchorPoint( ccp(0, 0.5f) );

    CCScaleBy *scale = CCScaleBy::actionWithDuration(4, 0.8f);
    CCActionInterval *scaleBack = scale->reverse();

    CCFiniteTimeAction* seq = CCSequence::actions(scale, scaleBack, NULL);

    map->runAction(CCRepeatForever::actionWithAction((CCActionInterval *)seq));
}

std::string TileMapTest::title()
{
	return "TileMapAtlas";
}

//------------------------------------------------------------------
//
// TileMapEditTest
//
//------------------------------------------------------------------
TileMapEditTest::TileMapEditTest()
{
	CCTileMapAtlas* map = CCTileMapAtlas::tileMapAtlasWithTileFile(s_TilesPng, s_LevelMapTga, 16, 16);
	// Create an Aliased Atlas
	map->getTexture()->setAliasTexParameters();

	CCSize s = map->getContentSize();
	////----UXLOG("ContentSize: %f, %f", s.width,s.height);

	// If you are not going to use the Map, you can free it now
	// [tilemap releaseMap);
	// And if you are going to use, it you can access the data with:
	schedule(schedule_selector(TileMapEditTest::updateMap), 0.2f);//:@selector(updateMap:) interval:0.2f);

	addChild(map, 0, kTagTileMap);

	map->setAnchorPoint( ccp(0, 0) );
	map->setPosition( ccp(-20,-200) );
}

void TileMapEditTest::updateMap(ccTime dt)
{
	// IMPORTANT
	//   The only limitation is that you cannot change an empty, or assign an empty tile to a tile
	//   The value 0 not rendered so don't assign or change a tile with value 0

	CCTileMapAtlas* tilemap = (CCTileMapAtlas*) getChildByTag(kTagTileMap);

	//
	// For example you can iterate over all the tiles
	// using this code, but try to avoid the iteration
	// over all your tiles in every frame. It's very expensive
	//	for(int x=0; x < tilemap.tgaInfo->width; x++) {
	//		for(int y=0; y < tilemap.tgaInfo->height; y++) {
	//			ccColor3B c =[tilemap tileAt:ccg(x,y));
	//			if( c.r != 0 ) {
	//				////----UXLOG("%d,%d = %d", x,y,c.r);
	//			}
	//		}
	//	}

	// NEW since v0.7
	ccColor3B c = tilemap->tileAt(ccg(13,21));
	c.r++;
	c.r %= 50;
	if( c.r==0)
		c.r=1;

	// NEW since v0.7
	tilemap->setTile(c, ccg(13,21) );
}

std::string TileMapEditTest::title()
{
	return "Editable TileMapAtlas";
}

//------------------------------------------------------------------
//
// TMXOrthoTest
//
//------------------------------------------------------------------
TMXOrthoTest::TMXOrthoTest()
{
	//
	// Test orthogonal with 3d camera and anti-alias textures
	//
	// it should not flicker. No artifacts should appear
	//
	//CCLayerColor* color = CCLayerColor::layerWithColor( ccc4(64,64,64,255) );
	//addChild(color, -1);

	CCTMXTiledMap* map = CCTMXTiledMap::tiledMapWithTMXFile("TileMaps/orthogonal-test2.tmx");
	addChild(map, 0, kTagTileMap);

	CCSize s = map->getContentSize();
	////----UXLOG("ContentSize: %f, %f", s.width,s.height);

	CCArray * pChildrenArray = map->getChildren();
	CCSpriteBatchNode* child = NULL;
    CCObject* pObject = NULL;
	CCARRAY_FOREACH(pChildrenArray, pObject)
	{
		child = (CCSpriteBatchNode*)pObject;

		if(!child)
			break;

		child->getTexture()->setAntiAliasTexParameters();
	}

	float x, y, z;
	map->getCamera()->getEyeXYZ(&x, &y, &z);
	map->getCamera()->setEyeXYZ(x-200, y, z+300);
}

void TMXOrthoTest::onEnter()
{
	TileDemo::onEnter();

	CCDirector::sharedDirector()->setProjection(CCDirectorProjection3D);
}

void TMXOrthoTest::onExit()
{
	CCDirector::sharedDirector()->setProjection(CCDirectorProjection2D);
	TileDemo::onExit();
}

std::string TMXOrthoTest::title()
{
	return "TMX Orthogonal test";
}

//------------------------------------------------------------------
//
// TMXOrthoTest2
//
//------------------------------------------------------------------
TMXOrthoTest2::TMXOrthoTest2()
{
	CCTMXTiledMap* map = CCTMXTiledMap::tiledMapWithTMXFile("TileMaps/orthogonal-test1.tmx");
	addChild(map, 0, kTagTileMap);

	CCSize s = map->getContentSize();
	////----UXLOG("ContentSize: %f, %f", s.width,s.height);

	CCArray* pChildrenArray = map->getChildren();
	CCSpriteBatchNode* child = NULL;
    CCObject* pObject = NULL;
	CCARRAY_FOREACH(pChildrenArray, pObject)
	{
		child = (CCSpriteBatchNode*)pObject;

		if(!child)
			break;

		child->getTexture()->setAntiAliasTexParameters();
	}

	map->runAction( CCScaleBy::actionWithDuration(2, 0.5f) ) ;
}

std::string TMXOrthoTest2::title()
{
	return "TMX Ortho test2";
}

//------------------------------------------------------------------
//
// TMXOrthoTest3
//
//------------------------------------------------------------------
TMXOrthoTest3::TMXOrthoTest3()
{
	CCTMXTiledMap *map = CCTMXTiledMap::tiledMapWithTMXFile("TileMaps/orthogonal-test3.tmx");
	addChild(map, 0, kTagTileMap);

	CCSize s = map->getContentSize();
	////----UXLOG("ContentSize: %f, %f", s.width,s.height);

	CCArray* pChildrenArray = map->getChildren();
	CCSpriteBatchNode* child = NULL;
	CCObject* pObject = NULL;
	CCARRAY_FOREACH(pChildrenArray, pObject)
	{
		child = (CCSpriteBatchNode*)pObject;

		if(!child)
			break;

		child->getTexture()->setAntiAliasTexParameters();
	}

	map->setScale(0.2f);
	map->setAnchorPoint( ccp(0.5f, 0.5f) );
}

std::string TMXOrthoTest3::title()
{
	return "TMX anchorPoint test";
}

//------------------------------------------------------------------
//
// TMXOrthoTest4
//
//------------------------------------------------------------------
TMXOrthoTest4::TMXOrthoTest4()
{
	CCTMXTiledMap *map = CCTMXTiledMap::tiledMapWithTMXFile("TileMaps/orthogonal-test4.tmx");
	addChild(map, 0, kTagTileMap);

	CCSize s1 = map->getContentSize();
	////----UXLOG("ContentSize: %f, %f", s1.width,s1.height);

	CCArray* pChildrenArray = map->getChildren();
	CCSpriteBatchNode* child = NULL;
	CCObject* pObject = NULL;
	CCARRAY_FOREACH(pChildrenArray, pObject)
	{
		child = (CCSpriteBatchNode*)pObject;

		if(!child)
			break;

		child->getTexture()->setAntiAliasTexParameters();
	}

	map->setAnchorPoint(ccp(0, 0));

	CCTMXLayer* layer = map->layerNamed("Layer 0");
	CCSize s = layer->getLayerSize();

	CCSprite* sprite;
	sprite = layer->tileAt(ccp(0,0));
	sprite->setScale(2);
	sprite = layer->tileAt(ccp(s.width-1,0));
	sprite->setScale(2);
	sprite = layer->tileAt(ccp(0,s.height-1));
	sprite->setScale(2);
	sprite = layer->tileAt(ccp(s.width-1,s.height-1));
	sprite->setScale(2);

	schedule( schedule_selector(TMXOrthoTest4::removeSprite), 2 );

}

void TMXOrthoTest4::removeSprite(ccTime dt)
{
	unschedule(schedule_selector(TMXOrthoTest4::removeSprite));

	CCTMXTiledMap *map = (CCTMXTiledMap*)getChildByTag(kTagTileMap);
	CCTMXLayer* layer = map->layerNamed("Layer 0");
	CCSize s = layer->getLayerSize();

	CCSprite* sprite = layer->tileAt( ccp(s.width-1,0) );
	layer->removeChild(sprite, true);
}

std::string TMXOrthoTest4::title()
{
	return "TMX width/height test";
}

//------------------------------------------------------------------
//
// TMXReadWriteTest
//
//------------------------------------------------------------------
enum
{
	SID_UPDATECOL = 100,
	SID_REPAINTWITHGID,
	SID_REMOVETILES
};

TMXReadWriteTest::TMXReadWriteTest()
{
	m_gid = 0;

	CCTMXTiledMap* map = CCTMXTiledMap::tiledMapWithTMXFile("TileMaps/orthogonal-test2.tmx");
	addChild(map, 0, kTagTileMap);

	CCSize s = map->getContentSize();
	////----UXLOG("ContentSize: %f, %f", s.width,s.height);

	CCTMXLayer* layer = map->layerNamed("Layer 0");
	layer->getTexture()->setAntiAliasTexParameters();

	map->setScale( 1 );

	CCSprite *tile0 = layer->tileAt(ccp(1,63));
	CCSprite *tile1 = layer->tileAt(ccp(2,63));
	CCSprite *tile2 = layer->tileAt(ccp(3,62));//ccp(1,62));
	CCSprite *tile3 = layer->tileAt(ccp(2,62));
	tile0->setAnchorPoint( ccp(0.5f, 0.5f) );
	tile1->setAnchorPoint( ccp(0.5f, 0.5f) );
	tile2->setAnchorPoint( ccp(0.5f, 0.5f) );
	tile3->setAnchorPoint( ccp(0.5f, 0.5f) );

	CCActionInterval* move = CCMoveBy::actionWithDuration(0.5f, ccp(0,160));
	CCActionInterval* rotate = CCRotateBy::actionWithDuration(2, 360);
	CCActionInterval* scale = CCScaleBy::actionWithDuration(2, 5);
	CCActionInterval* opacity = CCFadeOut::actionWithDuration(2);
	CCActionInterval* fadein = CCFadeIn::actionWithDuration(2);
	CCActionInterval* scaleback = CCScaleTo::actionWithDuration(1, 1);
	CCActionInstant* finish = CCCallFuncN::actionWithTarget(this, callfuncN_selector(TMXReadWriteTest::removeSprite));
	CCFiniteTimeAction* seq0 = CCSequence::actions(move, rotate, scale, opacity, fadein, scaleback, finish, NULL);
	CCActionInterval* seq1 = (CCActionInterval*)(seq0->copy()->autorelease());
	CCActionInterval* seq2 = (CCActionInterval*)(seq0->copy()->autorelease());
	CCActionInterval* seq3 = (CCActionInterval*)(seq0->copy()->autorelease());

	tile0->runAction(seq0);
	tile1->runAction(seq1);
	tile2->runAction(seq2);
	tile3->runAction(seq3);

	m_gid = layer->tileGIDAt(ccp(0,63));
	////----UXLOG("Tile GID at:(0,63) is: %d", m_gid);

	schedule(schedule_selector(TMXReadWriteTest::updateCol), 2.0f);
	schedule(schedule_selector(TMXReadWriteTest::repaintWithGID), 2.0f);
	schedule(schedule_selector(TMXReadWriteTest::removeTiles), 1.0f);

	////----UXLOG("++++atlas quantity: %d", layer->textureAtlas()->getTotalQuads());
	////----UXLOG("++++children: %d", layer->getChildren()->count() );

	m_gid2 = 0;
}

void TMXReadWriteTest::removeSprite(CCNode* sender)
{
	////----UXLOG("removing tile: %x", sender);
	CCNode* p = ((CCNode*)sender)->getParent();

	if (p)
	{
        p->removeChild((CCNode*)sender, true);
	}

	//////----UXLOG("atlas quantity: %d", p->textureAtlas()->totalQuads());
}

void TMXReadWriteTest::updateCol(ccTime dt)
{
	CCTMXTiledMap* map = (CCTMXTiledMap*)getChildByTag(kTagTileMap);
	CCTMXLayer *layer = (CCTMXLayer*)map->getChildByTag(0);

	////----UXLOG("++++atlas quantity: %d", layer->textureAtlas()->getTotalQuads());
	////----UXLOG("++++children: %d", layer->getChildren()->count() );

	CCSize s = layer->getLayerSize();

	for( int y=0; y< s.height; y++ )
	{
		layer->setTileGID(m_gid2, ccp((float)3, (float)y));
	}

	m_gid2 = (m_gid2 + 1) % 80;
}

void TMXReadWriteTest::repaintWithGID(ccTime dt)
{
//	[self unschedule:_cmd);

	CCTMXTiledMap* map = (CCTMXTiledMap*)getChildByTag(kTagTileMap);
	CCTMXLayer *layer = (CCTMXLayer*)map->getChildByTag(0);

	CCSize s = layer->getLayerSize();
	for( int x=0; x<s.width;x++)
	{
		int y = (int)s.height-1;
		unsigned int tmpgid = layer->tileGIDAt( ccp((float)x, (float)y) );
		layer->setTileGID(tmpgid+1, ccp((float)x, (float)y));
	}
}

void TMXReadWriteTest::removeTiles(ccTime dt)
{
	unschedule(schedule_selector(TMXReadWriteTest::removeTiles));

	CCTMXTiledMap* map = (CCTMXTiledMap*)getChildByTag(kTagTileMap);
	CCTMXLayer *layer = (CCTMXLayer*)map->getChildByTag(0);
	CCSize s = layer->getLayerSize();

	for( int y=0; y< s.height; y++ )
	{
		layer->removeTileAt( ccp(5.0, (float)y) );
	}
}

std::string TMXReadWriteTest::title()
{
	return "TMX Read/Write test";
}

//------------------------------------------------------------------
//
// TMXHexTest
//
//------------------------------------------------------------------
TMXHexTest::TMXHexTest()
{
	CCLayerColor* color = CCLayerColor::layerWithColor( ccc4f(64,64,64,255) );
	addChild(color, -1);

	CCTMXTiledMap* map = CCTMXTiledMap::tiledMapWithTMXFile("TileMaps/hexa-test.tmx");
	addChild(map, 0, kTagTileMap);

	CCSize s = map->getContentSize();
	////----UXLOG("ContentSize: %f, %f", s.width,s.height);
}

std::string TMXHexTest::title()
{
	return "TMX Hex tes";
}

//------------------------------------------------------------------
//
// TMXIsoTest
//
//------------------------------------------------------------------
TMXIsoTest::TMXIsoTest()
{
	CCLayerColor* color = CCLayerColor::layerWithColor( ccc4f(64,64,64,255) );
	addChild(color, -1);

	CCTMXTiledMap* map = CCTMXTiledMap::tiledMapWithTMXFile("TileMaps/iso-test.tmx");
	addChild(map, 0, kTagTileMap);

	// move map to the center of the screen
	CCSize ms = map->getMapSize();
	CCSize ts = map->getTileSize();
	map->runAction( CCMoveTo::actionWithDuration(1.0f, ccp( -ms.width * ts.width/2, -ms.height * ts.height/2 )) );
}

std::string TMXIsoTest::title()
{
	return "TMX Isometric test 0";
}

//------------------------------------------------------------------
//
// TMXIsoTest1
//
//------------------------------------------------------------------
TMXIsoTest1::TMXIsoTest1()
{
	CCLayerColor* color = CCLayerColor::layerWithColor( ccc4f(64,64,64,255) );
	addChild(color, -1);

	CCTMXTiledMap *map = CCTMXTiledMap::tiledMapWithTMXFile("TileMaps/iso-test1.tmx");
	addChild(map, 0, kTagTileMap);

	CCSize s = map->getContentSize();
	////----UXLOG("ContentSize: %f, %f", s.width,s.height);

	map->setAnchorPoint(ccp(0.5f, 0.5f));
}

std::string TMXIsoTest1::title()
{
	return "TMX Isometric test + anchorPoint";
}

//------------------------------------------------------------------
//
// TMXIsoTest2
//
//------------------------------------------------------------------
TMXIsoTest2::TMXIsoTest2()
{
	CCLayerColor* color = CCLayerColor::layerWithColor( ccc4f(64,64,64,255) );
	addChild(color, -1);

	CCTMXTiledMap *map = CCTMXTiledMap::tiledMapWithTMXFile("TileMaps/iso-test2.tmx");
	addChild(map, 0, kTagTileMap);

	CCSize s = map->getContentSize();
	////----UXLOG("ContentSize: %f, %f", s.width,s.height);

	// move map to the center of the screen
	CCSize ms = map->getMapSize();
	CCSize ts = map->getTileSize();
	map->runAction( CCMoveTo::actionWithDuration(1.0f, ccp( -ms.width * ts.width/2, -ms.height * ts.height/2 ) ));
}

std::string TMXIsoTest2::title()
{
	return "TMX Isometric test 2";
}

//------------------------------------------------------------------
//
// TMXUncompressedTest
//
//------------------------------------------------------------------
TMXUncompressedTest::TMXUncompressedTest()
{
	CCLayerColor* color = CCLayerColor::layerWithColor( ccc4f(64,64,64,255) );
	addChild(color, -1);

	CCTMXTiledMap *map = CCTMXTiledMap::tiledMapWithTMXFile("TileMaps/iso-test2-uncompressed.tmx");
	addChild(map, 0, kTagTileMap);

	CCSize s = map->getContentSize();
	////----UXLOG("ContentSize: %f, %f", s.width,s.height);

	// move map to the center of the screen
	CCSize ms = map->getMapSize();
	CCSize ts = map->getTileSize();
	map->runAction(CCMoveTo::actionWithDuration(1.0f, ccp( -ms.width * ts.width/2, -ms.height * ts.height/2 ) ));

	// testing release map
	CCArray* pChildrenArray = map->getChildren();
	CCTMXLayer* layer;
    CCObject* pObject = NULL;
	CCARRAY_FOREACH(pChildrenArray, pObject)
	{
		layer= (CCTMXLayer*)pObject;

		if(!layer)
			break;

		layer->releaseMap();
	}

}

std::string TMXUncompressedTest::title()
{
	return "TMX Uncompressed test";
}

//------------------------------------------------------------------
//
// TMXTilesetTest
//
//------------------------------------------------------------------
TMXTilesetTest::TMXTilesetTest()
{
	CCTMXTiledMap *map = CCTMXTiledMap::tiledMapWithTMXFile("TileMaps/orthogonal-test5.tmx");
	addChild(map, 0, kTagTileMap);

	CCSize s = map->getContentSize();
	////----UXLOG("ContentSize: %f, %f", s.width,s.height);

	CCTMXLayer* layer;
	layer = map->layerNamed("Layer 0");
	layer->getTexture()->setAntiAliasTexParameters();

	layer = map->layerNamed("Layer 1");
	layer->getTexture()->setAntiAliasTexParameters();

	layer = map->layerNamed("Layer 2");
	layer->getTexture()->setAntiAliasTexParameters();
}

std::string TMXTilesetTest::title()
{
	return "TMX Tileset test";
}

//------------------------------------------------------------------
//
// TMXOrthoObjectsTest
//
//------------------------------------------------------------------
TMXOrthoObjectsTest::TMXOrthoObjectsTest()
{
	CCTMXTiledMap *map = CCTMXTiledMap::tiledMapWithTMXFile("TileMaps/ortho-objects.tmx");
	addChild(map, -1, kTagTileMap);

	CCSize s = map->getContentSize();
	////----UXLOG("ContentSize: %f, %f", s.width,s.height);

	////----UXLOG("----> Iterating over all the group objets");
	CCTMXObjectGroup* group = map->objectGroupNamed("Object Group 1");
	CCMutableArray<CCStringToStringDictionary*> * objects = group->getObjects();

	CCStringToStringDictionary* dict;
	CCMutableArray<CCStringToStringDictionary*>::CCMutableArrayIterator it;
	for( it = objects->begin(); it != objects->end(); it++)
	{
		dict = (*it);//dynamic_cast<CCStringToStringDictionary*>(*it);

		if(!dict)
			break;

		////----UXLOG("object: %x", dict);
	}

	////----UXLOG("----> Fetching 1 object by name");
	// CCStringToStringDictionary* platform = group->objectNamed("platform");
	////----UXLOG("platform: %x", platform);
}

void TMXOrthoObjectsTest::draw()
{
	CCTMXTiledMap* map = (CCTMXTiledMap*) getChildByTag(kTagTileMap);
	CCTMXObjectGroup* group = map->objectGroupNamed("Object Group 1");

	CCMutableArray<CCStringToStringDictionary*> * objects = group->getObjects();
	CCStringToStringDictionary* dict;
	CCMutableArray<CCStringToStringDictionary*>::CCMutableArrayIterator it;

	for( it = objects->begin(); it != objects->end(); it++)
	{
		dict = (*it);//dynamic_cast<CCStringToStringDictionary*>(*it);

		if(!dict)
			break;
		std::string key = "x";
		int x = dict->objectForKey(key)->toInt();
		key = "y";
		int y = dict->objectForKey(key)->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("y"))->getNumber();
		key = "width";
		int width = dict->objectForKey(key)->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("width"))->getNumber();
		key = "height";
		int height = dict->objectForKey(key)->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("height"))->getNumber();

		glLineWidth(3);

		ccDrawLine( ccp((float)x, (float)y), ccp((float)(x+width), (float)y) );
		ccDrawLine( ccp((float)(x+width), (float)y), ccp((float)(x+width), (float)(y+height)) );
		ccDrawLine( ccp((float)(x+width), (float)(y+height)), ccp((float)x, (float)(y+height)) );
		ccDrawLine( ccp((float)x, (float)(y+height)), ccp((float)x, (float)y) );

		glLineWidth(1);
	}
}

std::string TMXOrthoObjectsTest::title()
{
	return "TMX Ortho object test";
}

std::string TMXOrthoObjectsTest::subtitle()
{
	return "You should see a white box around the 3 platforms";
}

//------------------------------------------------------------------
//
// TMXIsoObjectsTest
//
//------------------------------------------------------------------

TMXIsoObjectsTest::TMXIsoObjectsTest()
{
	CCTMXTiledMap* map = CCTMXTiledMap::tiledMapWithTMXFile("TileMaps/iso-test-objectgroup.tmx");
	addChild(map, -1, kTagTileMap);

	CCSize s = map->getContentSize();
	////----UXLOG("ContentSize: %f, %f", s.width,s.height);

	CCTMXObjectGroup* group = map->objectGroupNamed("Object Group 1");

    //UxMutableArray* objects = group->objects();
	CCMutableArray<CCStringToStringDictionary*> * objects = group->getObjects();
	//UxMutableDictionary<std::string>* dict;
    CCStringToStringDictionary* dict;
	//CCMutableArray<CCObject*>::CCMutableArrayIterator it;
    CCMutableArray<CCStringToStringDictionary*>::CCMutableArrayIterator it;

	for( it = objects->begin(); it != objects->end(); it++)
	{
		dict = (*it);

		if(!dict)
			break;

		////----UXLOG("object: %x", dict);
	}
}

void TMXIsoObjectsTest::draw()
{
	CCTMXTiledMap *map = (CCTMXTiledMap*) getChildByTag(kTagTileMap);
	CCTMXObjectGroup *group = map->objectGroupNamed("Object Group 1");

	CCMutableArray<CCStringToStringDictionary*> * objects = group->getObjects();
	CCStringToStringDictionary* dict;
	CCMutableArray<CCStringToStringDictionary*>::CCMutableArrayIterator it;

	for( it = objects->begin(); it != objects->end(); it++)
	{
		dict = (*it);//dynamic_cast<CCStringToStringDictionary*>(*it);

		if(!dict)
			break;
		std::string key = "x";
		int x = dict->objectForKey(key)->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("x"))->getNumber();
		key = "y";
		int y = dict->objectForKey(key)->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("y"))->getNumber();
		key = "width";
		int width = dict->objectForKey(key)->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("width"))->getNumber();
		key = "height";
		int height = dict->objectForKey(key)->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("height"))->getNumber();

		glLineWidth(3);

		ccDrawLine( ccp(x,y), ccp(x+width,y) );
		ccDrawLine( ccp(x+width,y), ccp(x+width,y+height) );
		ccDrawLine( ccp(x+width,y+height), ccp(x,y+height) );
		ccDrawLine( ccp(x,y+height), ccp(x,y) );

		glLineWidth(1);
	}
}

std::string TMXIsoObjectsTest::title()
{
	return "TMX Iso object test";
}

std::string TMXIsoObjectsTest::subtitle()
{
	return "You need to parse them manually. See bug #810";
}

//------------------------------------------------------------------
//
// TMXResizeTest
//
//------------------------------------------------------------------

TMXResizeTest::TMXResizeTest()
{
	CCTMXTiledMap* map = CCTMXTiledMap::tiledMapWithTMXFile("TileMaps/orthogonal-test5.tmx");
	addChild(map, 0, kTagTileMap);

	CCSize s = map->getContentSize();
	////----UXLOG("ContentSize: %f, %f", s.width,s.height);

	CCTMXLayer* layer;
	layer = map->layerNamed("Layer 0");

	CCSize ls = layer->getLayerSize();
	for (unsigned int y = 0; y < ls.height; y++)
	{
		for (unsigned int x = 0; x < ls.width; x++)
		{
			layer->setTileGID(1, ccp( x, y ) );
		}
	}
}

std::string TMXResizeTest::title()
{
	return "TMX resize test";
}

std::string TMXResizeTest::subtitle()
{
	return "Should not crash. Testing issue #740";
}

//------------------------------------------------------------------
//
// TMXIsoZorder
//
//------------------------------------------------------------------
TMXIsoZorder::TMXIsoZorder()
{
	CCTMXTiledMap *map = CCTMXTiledMap::tiledMapWithTMXFile("TileMaps/iso-test-zorder.tmx");
	addChild(map, 0, kTagTileMap);

	CCSize s = map->getContentSize();
	////----UXLOG("ContentSize: %f, %f", s.width,s.height);
    map->setPosition(ccp(-s.width/2,0));

	m_tamara = CCSprite::spriteWithFile(s_pPathSister1);
	map->addChild(m_tamara, map->getChildren()->count() );
	m_tamara->retain();
	int mapWidth = map->getMapSize().width * map->getTileSize().width;
	m_tamara->setPositionInPixels(ccp( mapWidth/2,0));
	m_tamara->setAnchorPoint(ccp(0.5f,0));

	CCActionInterval* move = CCMoveBy::actionWithDuration(10, ccpMult(ccp(300,250), 1/CC_CONTENT_SCALE_FACTOR()));
	CCActionInterval* back = move->reverse();
	CCFiniteTimeAction* seq = CCSequence::actions(move, back,NULL);
	m_tamara->runAction( CCRepeatForever::actionWithAction((CCActionInterval*) seq) );

	schedule( schedule_selector(TMXIsoZorder::repositionSprite) );
}

TMXIsoZorder::~TMXIsoZorder()
{
	m_tamara->release();
}

void TMXIsoZorder::onExit()
{
    unschedule(schedule_selector(TMXIsoZorder::repositionSprite));
	TileDemo::onExit();
}

void TMXIsoZorder::repositionSprite(ccTime dt)
{
	CCPoint p = m_tamara->getPositionInPixels();
	CCNode *map = getChildByTag(kTagTileMap);

	// there are only 4 layers. (grass and 3 trees layers)
	// if tamara < 48, z=4
	// if tamara < 96, z=3
	// if tamara < 144,z=2

	int newZ = 4 - (p.y / 48);
	newZ = max(newZ,0);

	map->reorderChild(m_tamara, newZ);
}

std::string TMXIsoZorder::title()
{
	return "TMX Iso Zorder";
}

std::string TMXIsoZorder::subtitle()
{
	return "Sprite should hide behind the trees";
}

//------------------------------------------------------------------
//
// TMXOrthoZorder
//
//------------------------------------------------------------------
TMXOrthoZorder::TMXOrthoZorder()
{
	CCTMXTiledMap *map = CCTMXTiledMap::tiledMapWithTMXFile("TileMaps/orthogonal-test-zorder.tmx");
	addChild(map, 0, kTagTileMap);

	CCSize s = map->getContentSize();
	////----UXLOG("ContentSize: %f, %f", s.width,s.height);

	m_tamara = CCSprite::spriteWithFile(s_pPathSister1);
	map->addChild(m_tamara,  map->getChildren()->count());
	m_tamara->retain();
	m_tamara->setAnchorPoint(ccp(0.5f,0));

	CCActionInterval* move = CCMoveBy::actionWithDuration(10, ccpMult(ccp(400,450), 1/CC_CONTENT_SCALE_FACTOR() ));
	CCActionInterval* back = move->reverse();
	CCFiniteTimeAction* seq = CCSequence::actions(move, back,NULL);
	m_tamara->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq));

	schedule( schedule_selector(TMXOrthoZorder::repositionSprite));
}

TMXOrthoZorder::~TMXOrthoZorder()
{
	m_tamara->release();
}

void TMXOrthoZorder::repositionSprite(ccTime dt)
{
	CCPoint p = m_tamara->getPositionInPixels();
	CCNode* map = getChildByTag(kTagTileMap);

	// there are only 4 layers. (grass and 3 trees layers)
	// if tamara < 81, z=4
	// if tamara < 162, z=3
	// if tamara < 243,z=2

	// -10: customization for this particular sample
	int newZ = 4 - ( (p.y-10) / 81);
	newZ = max(newZ,0);

	map->reorderChild(m_tamara, newZ);
}

std::string TMXOrthoZorder::title()
{
	return "TMX Ortho Zorder";
}

std::string TMXOrthoZorder::subtitle()
{
	return "Sprite should hide behind the trees";
}

//------------------------------------------------------------------
//
// TMXIsoVertexZ
//
//------------------------------------------------------------------
TMXIsoVertexZ::TMXIsoVertexZ()
{
	CCTMXTiledMap *map = CCTMXTiledMap::tiledMapWithTMXFile("TileMaps/iso-test-vertexz.tmx");
	addChild(map, 0, kTagTileMap);

	CCSize s = map->getContentSize();
    map->setPosition( ccp(-s.width/2,0) );
	////----UXLOG("ContentSize: %f, %f", s.width,s.height);

	// because I'm lazy, I'm reusing a tile as an sprite, but since this method uses vertexZ, you
	// can use any CCSprite and it will work OK.
	CCTMXLayer* layer = map->layerNamed("Trees");
	m_tamara = layer->tileAt( ccp(29,29) );
	m_tamara->retain();

	CCActionInterval* move = CCMoveBy::actionWithDuration(10, ccpMult( ccp(300,250), 1/CC_CONTENT_SCALE_FACTOR() ) );
	CCActionInterval* back = move->reverse();
	CCFiniteTimeAction* seq = CCSequence::actions(move, back,NULL);
	m_tamara->runAction( CCRepeatForever::actionWithAction((CCActionInterval*) seq) );

	schedule( schedule_selector(TMXIsoVertexZ::repositionSprite));

}

TMXIsoVertexZ::~TMXIsoVertexZ()
{
	m_tamara->release();
}

void TMXIsoVertexZ::repositionSprite(ccTime dt)
{
	// tile height is 64x32
	// map size: 30x30
	CCPoint p = m_tamara->getPositionInPixels();
	m_tamara->setVertexZ( -( (p.y+32) /16) );
}

void TMXIsoVertexZ::onEnter()
{
	TileDemo::onEnter();

	// TIP: 2d projection should be used
	CCDirector::sharedDirector()->setProjection(kCCDirectorProjection2D);
}

void TMXIsoVertexZ::onExit()
{
	// At exit use any other projection.
	//	CCDirector::sharedDirector()->setProjection:kCCDirectorProjection3D);
	TileDemo::onExit();
}

std::string TMXIsoVertexZ::title()
{
	return "TMX Iso VertexZ";
}

std::string TMXIsoVertexZ::subtitle()
{
	return "Sprite should hide behind the trees";
}

//------------------------------------------------------------------
//
// TMXOrthoVertexZ
//
//------------------------------------------------------------------
TMXOrthoVertexZ::TMXOrthoVertexZ()
{
	CCTMXTiledMap *map = CCTMXTiledMap::tiledMapWithTMXFile("TileMaps/orthogonal-test-vertexz.tmx");
	addChild(map, 0, kTagTileMap);

	CCSize s = map->getContentSize();
	////----UXLOG("ContentSize: %f, %f", s.width,s.height);

	// because I'm lazy, I'm reusing a tile as an sprite, but since this method uses vertexZ, you
	// can use any CCSprite and it will work OK.
	CCTMXLayer* layer = map->layerNamed("trees");
	m_tamara = layer->tileAt(ccp(0,11));
    CCLOG("%p vertexZ: %f", m_tamara, m_tamara->getVertexZ());
	m_tamara->retain();

	CCActionInterval* move = CCMoveBy::actionWithDuration(10, ccpMult( ccp(400,450), 1/CC_CONTENT_SCALE_FACTOR()));
	CCActionInterval* back = move->reverse();
	CCFiniteTimeAction* seq = CCSequence::actions(move, back,NULL);
	m_tamara->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq));

	schedule(schedule_selector(TMXOrthoVertexZ::repositionSprite));

}

TMXOrthoVertexZ::~TMXOrthoVertexZ()
{
	m_tamara->release();
}

void TMXOrthoVertexZ::repositionSprite(ccTime dt)
{
	// tile height is 101x81
	// map size: 12x12
	CCPoint p = m_tamara->getPositionInPixels();
	m_tamara->setVertexZ( -( (p.y+81) /81) );
}

void TMXOrthoVertexZ::onEnter()
{
	TileDemo::onEnter();

	// TIP: 2d projection should be used
	CCDirector::sharedDirector()->setProjection(kCCDirectorProjection2D);
}

void TMXOrthoVertexZ::onExit()
{
	// At exit use any other projection.
	//	CCDirector::sharedDirector()->setProjection:kCCDirectorProjection3D);
	TileDemo::onExit();
}

std::string TMXOrthoVertexZ::title()
{
	return "TMX Ortho vertexZ";
}

std::string TMXOrthoVertexZ::subtitle()
{
	return "Sprite should hide behind the trees";
}

//------------------------------------------------------------------
//
// TMXIsoMoveLayer
//
//------------------------------------------------------------------
TMXIsoMoveLayer::TMXIsoMoveLayer()
{
	CCTMXTiledMap* map = CCTMXTiledMap::tiledMapWithTMXFile("TileMaps/iso-test-movelayer.tmx");
	addChild(map, 0, kTagTileMap);

	map->setPosition(ccp(-700,-50));

	CCSize s = map->getContentSize();
	////----UXLOG("ContentSize: %f, %f", s.width,s.height);
}

std::string TMXIsoMoveLayer::title()
{
	return "TMX Iso Move Layer";
}

std::string TMXIsoMoveLayer::subtitle()
{
	return "Trees should be horizontally aligned";
}

//------------------------------------------------------------------
//
// TMXOrthoMoveLayer
//
//------------------------------------------------------------------
TMXOrthoMoveLayer::TMXOrthoMoveLayer()
{
	CCTMXTiledMap *map = CCTMXTiledMap::tiledMapWithTMXFile("TileMaps/orthogonal-test-movelayer.tmx");
	addChild(map, 0, kTagTileMap);

	CCSize s = map->getContentSize();
	////----UXLOG("ContentSize: %f, %f", s.width,s.height);
}

std::string TMXOrthoMoveLayer::title()
{
	return "TMX Ortho Move Layer";
}

std::string TMXOrthoMoveLayer::subtitle()
{
	return "Trees should be horizontally aligned";
}

//------------------------------------------------------------------
//
// TMXBug987
//
//------------------------------------------------------------------
TMXBug987::TMXBug987()
{
    CCTMXTiledMap *map = CCTMXTiledMap::tiledMapWithTMXFile("TileMaps/orthogonal-test6.tmx");
    addChild(map, 0, kTagTileMap);

    CCSize s1 = map->getContentSize();
    CCLOG("ContentSize: %f, %f", s1.width,s1.height);

    CCArray* childs = map->getChildren();
    CCTMXLayer* pNode;
    CCObject* pObject = NULL;
    CCARRAY_FOREACH(childs, pObject)
    {
        pNode = (CCTMXLayer*) pObject;
        CC_BREAK_IF(!pNode);
        pNode->getTexture()->setAntiAliasTexParameters();
    }

    map->setAnchorPoint(ccp(0, 0));
    CCTMXLayer *layer = map->layerNamed("Tile Layer 1");
    layer->setTileGID(3, ccp(2,2));
}

std::string TMXBug987::title()
{
    return "TMX Bug 987";
}

std::string TMXBug987::subtitle()
{
    return "You should see an square";
}

//------------------------------------------------------------------
//
// TMXBug787
//
//------------------------------------------------------------------
TMXBug787::TMXBug787()
{
    CCTMXTiledMap *map = CCTMXTiledMap::tiledMapWithTMXFile("TileMaps/iso-test-bug787.tmx");
    addChild(map, 0, kTagTileMap);

    map->setScale(0.25f);
}

std::string TMXBug787::title()
{
    return "TMX Bug 787";
}

std::string TMXBug787::subtitle()
{
    return "You should see a map";
}

//------------------------------------------------------------------
//
// TileDemo
//
//------------------------------------------------------------------

enum
{
	IDC_NEXT = 100,
	IDC_BACK,
	IDC_RESTART
};

static int sceneIdx = -1;

#define MAX_LAYER	25

CCLayer* createTileMapLayer(int nIndex)
{
	switch(nIndex)
	{
		case 0: return new TMXIsoZorder();
		case 1: return new TMXOrthoZorder();
		case 2: return new TMXIsoVertexZ();
		case 3: return new TMXOrthoVertexZ();
		case 4: return new TMXOrthoTest();
		case 5: return new TMXOrthoTest2();
		case 6: return new TMXOrthoTest3();
		case 7: return new TMXOrthoTest4();
		case 8: return new TMXIsoTest();
		case 9: return new TMXIsoTest1();
		case 10: return new TMXIsoTest2();
		case 11: return new TMXUncompressedTest ();
		case 12: return new TMXHexTest();
		case 13: return new TMXReadWriteTest();
		case 14: return new TMXTilesetTest();
		case 15: return new TMXOrthoObjectsTest();
		case 16: return new TMXIsoObjectsTest();
		case 17: return new TMXResizeTest();
		case 18: return new TMXIsoMoveLayer();
		case 19: return new TMXOrthoMoveLayer();
		case 20: return new TileMapTest();
		case 21: return new TileMapEditTest();
        case 22: return new TMXBug987();
        case 23: return new TMXBug787();
		case 24: return new TMXGIDObjectsTest();
	}

	return NULL;
}

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

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

	return pLayer;
}

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

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

	return pLayer;
}

CCLayer* restartTileMapAction()
{
	CCLayer* pLayer = createTileMapLayer(sceneIdx);
	pLayer->autorelease();

	return pLayer;
}

TileDemo::TileDemo(void)
{
	setIsTouchEnabled( true );

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

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

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

		m_subtitle = l;
		m_subtitle->retain();
	}

	CCMenuItemImage *item1 = CCMenuItemImage::itemFromNormalImage(s_pPathB1, s_pPathB2, this, menu_selector(TileDemo::backCallback) );
	CCMenuItemImage *item2 = CCMenuItemImage::itemFromNormalImage(s_pPathR1, s_pPathR2, this, menu_selector(TileDemo::restartCallback) );
	CCMenuItemImage *item3 = CCMenuItemImage::itemFromNormalImage(s_pPathF1, s_pPathF2, this, menu_selector(TileDemo::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);
}

TileDemo::~TileDemo(void)
{
	m_label->release();
	m_subtitle->release();
}

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

std::string TileDemo::subtitle()
{
	return "drag the screen";
}

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

	m_label->setString(title().c_str());
	m_subtitle->setString(subtitle().c_str());
}

void TileDemo::restartCallback(CCObject* pSender)
{
	CCScene* s = new TileMapTestScene();
	s->addChild(restartTileMapAction());

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

void TileDemo::nextCallback(CCObject* pSender)
{
	CCScene* s = new TileMapTestScene();
	s->addChild( nextTileMapAction() );
	CCDirector::sharedDirector()->replaceScene(s);
	s->release();
}

void TileDemo::backCallback(CCObject* pSender)
{
	CCScene* s = new TileMapTestScene();
	s->addChild( backTileMapAction() );
	CCDirector::sharedDirector()->replaceScene(s);
	s->release();
}

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

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

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

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

void TileDemo::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(kTagTileMap);
	CCPoint currentPos = node->getPosition();
	node->setPosition( ccpAdd(currentPos, diff) );
}

void TileMapTestScene::runThisTest()
{
    CCLayer* pLayer = nextTileMapAction();
    addChild(pLayer);

	// fix bug #486, #419.
	// "test" is the default value in CCDirector::setGLDefaultValues()
	// but TransitionTest may setDepthTest(false), we should revert it here
	CCDirector::sharedDirector()->setDepthTest(true);

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

TMXGIDObjectsTest::TMXGIDObjectsTest()
{
	CCTMXTiledMap *map = CCTMXTiledMap::tiledMapWithTMXFile("TileMaps/test-object-layer.tmx");
	addChild(map, -1, kTagTileMap);

	CCSize s = map->getContentSize();
	CCLOG("Contentsize: %f, %f", s.width, s.height);

	CCLOG("----> Iterating over all the group objets");
	//CCTMXObjectGroup *group = map->objectGroupNamed("Object Layer 1");

}

void TMXGIDObjectsTest::draw()
{
	CCTMXTiledMap *map = (CCTMXTiledMap*)getChildByTag(kTagTileMap);
	CCTMXObjectGroup *group = map->objectGroupNamed("Object Layer 1");

	CCMutableArray<CCStringToStringDictionary*> *array = group->getObjects();
	CCMutableArray<CCStringToStringDictionary*>::CCMutableArrayIterator iter;
	CCStringToStringDictionary *dict;

	for (iter = array->begin(); iter != array->end(); ++iter)
	{
		dict = *iter;
		if(!dict)
		{
			break;
		}

		std::string key = "x";
		int x = dict->objectForKey(key)->toInt();
		key = "y";
		int y = dict->objectForKey(key)->toInt();
		key = "width";
		int width = dict->objectForKey(key)->toInt();
		key = "height";
		int height = dict->objectForKey(key)->toInt();

		glLineWidth(3);

		ccDrawLine(ccp(x, y), ccp(x + width, y));
		ccDrawLine(ccp(x + width, y), ccp(x + width, y + height));
		ccDrawLine(ccp(x + width,y + height), ccp(x,y + height));
		ccDrawLine(ccp(x,y + height), ccp(x,y));

		glLineWidth(1);
	}
}

string TMXGIDObjectsTest::title()
{
	return "TMX GID objects";
}

string TMXGIDObjectsTest::subtitle()
{
	return "Tiles are created from an object group";
}


code:
#ifndef _TILEMAP_TEST_H_
#define _TILEMAP_TEST_H_

#include "../testBasic.h"

class TileDemo : public CCLayer
{
protected:
	CCLabelTTF* m_label;
	CCLabelTTF* m_subtitle;

public:
	TileDemo(void);
	virtual ~TileDemo(void);

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

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

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

class TileMapTest : public TileDemo
{
public:
	TileMapTest(void);
	virtual std::string title();
};

class TileMapEditTest : public TileDemo
{
public:
	TileMapEditTest (void);
	virtual std::string title();

	void updateMap(ccTime dt);
};

class TMXOrthoTest : public TileDemo
{
public:
	TMXOrthoTest(void);
	virtual std::string title();

	virtual void onEnter();
	virtual void onExit();
};

class TMXOrthoTest2 : public TileDemo
{
public:
	TMXOrthoTest2(void);
	virtual std::string title();
};

class TMXOrthoTest3 : public TileDemo
{
public:
	TMXOrthoTest3(void);
	virtual std::string title();
};

class TMXOrthoTest4 : public TileDemo
{
public:
	TMXOrthoTest4(void);
	void removeSprite(ccTime dt);
	virtual std::string title();
};

class TMXReadWriteTest : public TileDemo
{
	unsigned int m_gid;
	unsigned int m_gid2;
public:
	TMXReadWriteTest(void);
	virtual std::string title();

	void removeSprite(CCNode* sender);
	void updateCol(ccTime dt);
	void repaintWithGID(ccTime dt);
	void removeTiles(ccTime dt);
};

class TMXHexTest : public TileDemo
{
public:
	TMXHexTest(void);
	virtual std::string title();
};

class TMXIsoTest : public TileDemo
{
public:
	TMXIsoTest(void);
	virtual std::string title();
};

class TMXIsoTest1 : public TileDemo
{
public:
	TMXIsoTest1(void);
	virtual std::string title();
};

class TMXIsoTest2 : public TileDemo
{
public:
	TMXIsoTest2(void);
	virtual std::string title();
};

class TMXUncompressedTest : public TileDemo
{
public:
	TMXUncompressedTest(void);
	virtual std::string title();
};

class TMXTilesetTest : public TileDemo
{
public:
	TMXTilesetTest(void);
	virtual std::string title();
};

class TMXOrthoObjectsTest : public TileDemo
{
public:
	TMXOrthoObjectsTest(void);
	virtual std::string title();

	virtual void draw();
	virtual std::string subtitle();
};

class TMXIsoObjectsTest : public TileDemo
{
public:
	TMXIsoObjectsTest(void);
	virtual std::string title();

	virtual void draw();
	virtual std::string subtitle();
};

class TMXResizeTest : public TileDemo
{
public:
	TMXResizeTest(void);
	virtual std::string title();

	virtual std::string subtitle();
};

class TMXIsoZorder : public TileDemo
{
	CCSprite*	m_tamara;
public:
	TMXIsoZorder(void);
	virtual std::string title();
	virtual std::string subtitle();
	virtual void onExit(void);

	~TMXIsoZorder();
	void repositionSprite(ccTime dt);
};

class TMXOrthoZorder : public TileDemo
{
	CCSprite*	m_tamara;
public:
	TMXOrthoZorder(void);
	virtual std::string title();
	virtual std::string subtitle();

	virtual ~TMXOrthoZorder();
	void repositionSprite(ccTime dt);
};

class TMXIsoVertexZ : public TileDemo
{
	CCSprite*	m_tamara;
public:
	TMXIsoVertexZ(void);
	virtual std::string title();
	virtual std::string subtitle();

	~TMXIsoVertexZ();
	void repositionSprite(ccTime dt);
	virtual void onEnter();
	virtual void onExit();
};

class TMXOrthoVertexZ : public TileDemo
{
	CCSprite*	m_tamara;
public:
	TMXOrthoVertexZ(void);
	virtual std::string title();
	virtual std::string subtitle();

	~TMXOrthoVertexZ();
	void repositionSprite(ccTime dt);
	virtual void onEnter();
	virtual void onExit();
};

class TMXIsoMoveLayer : public TileDemo
{
public:
	TMXIsoMoveLayer(void);
	virtual std::string title();
	virtual std::string subtitle();
};

class TMXOrthoMoveLayer : public TileDemo
{
public:
	TMXOrthoMoveLayer(void);
	virtual std::string title();
	virtual std::string subtitle();
};

class TMXBug987 : public TileDemo
{
public:
    TMXBug987();
    virtual std::string title();
    virtual std::string subtitle();
};

class TMXBug787 : public TileDemo
{
public:
    TMXBug787();
    virtual std::string title();
    virtual std::string subtitle();
};

class TMXGIDObjectsTest : public TileDemo
{
public:
	TMXGIDObjectsTest();
	virtual std::string title();
	virtual std::string subtitle();
	virtual void draw();
};

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

#endif

license: mit


code:
#include "Ball.h"
#include "Paddle.h"

Ball::Ball(void)
{
}

Ball::~Ball(void)
{
}

float Ball::radius()
{
	return getTexture()->getContentSize().width / 2;
}

Ball* Ball::ballWithTexture(CCTexture2D* aTexture)
{
	Ball* pBall = new Ball();
	pBall->initWithTexture(aTexture);
	pBall->autorelease();

	return pBall;
}

void Ball::move(ccTime delta)
{
	this->setPosition( ccpAdd(getPosition(), ccpMult(m_velocity, delta)) );

	if (getPosition().x > 320 - radius())
	{
		setPosition( ccp( 320 - radius(), getPosition().y) );
		m_velocity.x *= -1;
	}
	else if (getPosition().x < radius())
	{
		setPosition( ccp(radius(), getPosition().y) );
		m_velocity.x *= -1;
	}
}

void Ball::collideWithPaddle(Paddle* paddle)
{
	CCRect paddleRect = paddle->rect();
	paddleRect.origin.x += paddle->getPosition().x;
	paddleRect.origin.y += paddle->getPosition().y;

    float lowY = CCRect::CCRectGetMinY(paddleRect);
	float midY = CCRect::CCRectGetMidY(paddleRect);
	float highY = CCRect::CCRectGetMaxY(paddleRect);

	float leftX = CCRect::CCRectGetMinX(paddleRect);
	float rightX = CCRect::CCRectGetMaxX(paddleRect);

	if (getPosition().x > leftX && getPosition().x < rightX) {

		bool hit = false;
		float angleOffset = 0.0f;

		if (getPosition().y > midY && getPosition().y <= highY + radius())
		{
			setPosition( CCPointMake(getPosition().x, highY + radius()) );
			hit = true;
			angleOffset = (float)M_PI / 2;
		}
		else if (getPosition().y < midY && getPosition().y >= lowY - radius())
		{
			setPosition( CCPointMake(getPosition().x, lowY - radius()) );
			hit = true;
			angleOffset = -(float)M_PI / 2;
		}

		if (hit)
		{
			float hitAngle = ccpToAngle(ccpSub(paddle->getPosition(), getPosition())) + angleOffset;

			float scalarVelocity = ccpLength(m_velocity) * 1.05f;
			float velocityAngle = -ccpToAngle(m_velocity) + 0.5f * hitAngle;

			m_velocity = ccpMult(ccpForAngle(velocityAngle), scalarVelocity);
		}
	}
}


code:
#ifndef _BALL_H_
#define _BALL_H_

#include "cocos2d.h"

class Paddle;

using namespace cocos2d;

class Ball : public CCSprite
{
	CCPoint m_velocity;
public:
	Ball(void);
	virtual ~Ball(void);

	float radius();
	//BOOL initWithTexture(CCTexture2D* aTexture);
	//virtual void setTexture(CCTexture2D* newTexture);
	void move(ccTime delta);
	void collideWithPaddle(Paddle* paddle);

public:
	void setVelocity(CCPoint velocity){m_velocity = velocity;}
	CCPoint getVelocity(){return m_velocity;}

public:
	static Ball* ballWithTexture(CCTexture2D* aTexture);
};

#endif


code:
#include "Paddle.h"

Paddle::Paddle(void)
{
}

Paddle::~Paddle(void)
{
}

CCRect Paddle::rect()
{
	CCSize s = getTexture()->getContentSize();
	return CCRectMake(-s.width / 2, -s.height / 2, s.width, s.height);
}

Paddle* Paddle::paddleWithTexture(CCTexture2D* aTexture)
{
	Paddle* pPaddle = new Paddle();
	pPaddle->initWithTexture( aTexture );
	pPaddle->autorelease();

	return pPaddle;
}

bool Paddle::initWithTexture(CCTexture2D* aTexture)
{
	if( CCSprite::initWithTexture(aTexture) )
	{
		m_state = kPaddleStateUngrabbed;
	}

	return true;
}

void Paddle::onEnter()
{
    CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, 0, true);
	CCSprite::onEnter();
}

void Paddle::onExit()
{
	CCTouchDispatcher::sharedDispatcher()->removeDelegate(this);
	CCSprite::onExit();
}

bool Paddle::containsTouchLocation(CCTouch* touch)
{
	return CCRect::CCRectContainsPoint(rect(), convertTouchToNodeSpaceAR(touch));
}

bool Paddle::ccTouchBegan(CCTouch* touch, CCEvent* event)
{
	if (m_state != kPaddleStateUngrabbed) return false;
	if ( !containsTouchLocation(touch) ) return false;

	m_state = kPaddleStateGrabbed;
	return true;
}

void Paddle::ccTouchMoved(CCTouch* touch, CCEvent* event)
{
	// If it weren't for the TouchDispatcher, you would need to keep a reference
	// to the touch from touchBegan and check that the current touch is the same
	// as that one.
	// Actually, it would be even more complicated since in the Cocos dispatcher
	// you get CCSets instead of 1 UITouch, so you'd need to loop through the set
	// in each touchXXX method.

	CCAssert(m_state == kPaddleStateGrabbed, L"Paddle - Unexpected state!");

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

	setPosition( CCPointMake(touchPoint.x, getPosition().y) );
}

void Paddle::ccTouchEnded(CCTouch* touch, CCEvent* event)
{
	CCAssert(m_state == kPaddleStateGrabbed, L"Paddle - Unexpected state!");

	m_state = kPaddleStateUngrabbed;
}

void Paddle::touchDelegateRetain()
{
	this->retain();
}

void Paddle::touchDelegateRelease()
{
	this->release();
}


code:
#ifndef _PADDLE_H_
#define _PADDLE_H_

#include "cocos2d.h"

using namespace cocos2d;

typedef enum tagPaddleState
{
	kPaddleStateGrabbed,
	kPaddleStateUngrabbed
} PaddleState;

class Paddle : public CCSprite, public CCTargetedTouchDelegate
{
	PaddleState		m_state;

public:
	Paddle(void);
	virtual ~Paddle(void);

	CCRect rect();
	bool initWithTexture(CCTexture2D* aTexture);
	virtual void onEnter();
	virtual void onExit();
	bool containsTouchLocation(CCTouch* touch);
	virtual bool ccTouchBegan(CCTouch* touch, CCEvent* event);
	virtual void ccTouchMoved(CCTouch* touch, CCEvent* event);
	virtual void ccTouchEnded(CCTouch* touch, CCEvent* event);

	virtual void touchDelegateRetain();
	virtual void touchDelegateRelease();

	static Paddle* paddleWithTexture(CCTexture2D* aTexture);
};

#endif


code:
#include "TouchesTest.h"
#include "Ball.h"
#include "Paddle.h"
#include "../testResource.h"

enum tagPlayer
{
	kHighPlayer,
	kLowPlayer
} PlayerTouches;

#define kStatusBarHeight 20.0f
//#define k1UpperLimit (480.0f - kStatusBarHeight)

enum
{
	kSpriteTag
};

//------------------------------------------------------------------
//
// PongScene
//
//------------------------------------------------------------------
PongScene::PongScene()
:TestScene(true)
{
	PongLayer *pongLayer = new PongLayer();//PongLayer::node();
	addChild(pongLayer);
    pongLayer->release();
}

void PongScene::MainMenuCallback(CCObject* pSender)
{
    CCDirector::sharedDirector()->setDeviceOrientation(CCDeviceOrientationPortrait);
    TestScene::MainMenuCallback(pSender);
}

//------------------------------------------------------------------
//
// PongLayer
//
//------------------------------------------------------------------
PongLayer::PongLayer()
{
	m_ballStartingVelocity = CCPointMake(20.0f, -100.0f);

    m_ball = Ball::ballWithTexture( CCTextureCache::sharedTextureCache()->addImage(s_Ball) );
	m_ball->setPosition( CCPointMake(160.0f, 240.0f) );
	m_ball->setVelocity( m_ballStartingVelocity );
	addChild( m_ball );
	m_ball->retain();

	CCTexture2D* paddleTexture = CCTextureCache::sharedTextureCache()->addImage(s_Paddle);

	CCMutableArray<CCObject *> *paddlesM = new CCMutableArray<CCObject *>(4);

	Paddle* paddle = Paddle::paddleWithTexture(paddleTexture);
	paddle->setPosition( CCPointMake(160, 15) );
	paddlesM->addObject( paddle );

	paddle = Paddle::paddleWithTexture( paddleTexture );
	paddle->setPosition( CCPointMake(160, 480 - kStatusBarHeight - 15) );
	paddlesM->addObject( paddle );

	paddle = Paddle::paddleWithTexture( paddleTexture );
	paddle->setPosition( CCPointMake(160, 100) );
	paddlesM->addObject( paddle );

	paddle = Paddle::paddleWithTexture( paddleTexture );
	paddle->setPosition( CCPointMake(160, 480 - kStatusBarHeight - 100) );
	paddlesM->addObject( paddle );

	m_paddles = paddlesM->copy();

    CCMutableArray<CCObject *>::CCMutableArrayIterator it;
	for(it = m_paddles->begin(); it != m_paddles->end(); it++)
	{
		paddle = (Paddle*)(*it);

		if(!paddle)
			break;

		addChild(paddle);
	}

	paddlesM->release();

	schedule( schedule_selector(PongLayer::doStep) );
}

PongLayer::~PongLayer()
{
	m_ball->release();
	m_paddles->release();
}

void PongLayer::resetAndScoreBallForPlayer(int player)
{
	m_ballStartingVelocity = ccpMult(m_ballStartingVelocity, -1.1f);
	m_ball->setVelocity( m_ballStartingVelocity );
	m_ball->setPosition( CCPointMake(160.0f, 240.0f) );

	// TODO -- scoring
}

void PongLayer::doStep(ccTime delta)
{
	m_ball->move(delta);

	Paddle* paddle;
    CCMutableArray<CCObject *>::CCMutableArrayIterator it;
	for(it = m_paddles->begin(); it != m_paddles->end(); it++)
	{
		paddle = (Paddle*)(*it);

		if(!paddle)
			break;

		m_ball->collideWithPaddle( paddle );
	}

	if (m_ball->getPosition().y > 480 - kStatusBarHeight + m_ball->radius())
		resetAndScoreBallForPlayer( kLowPlayer );
	else if (m_ball->getPosition().y < -m_ball->radius())
		resetAndScoreBallForPlayer( kHighPlayer );
    m_ball->draw();
}

void PongScene::runThisTest()
{
    CCDirector::sharedDirector()->replaceScene(this);
}


code:
#ifndef _TOUCHES_TEST__H_
#define _TOUCHES_TEST__H_

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

using namespace cocos2d;

class PongScene : public TestScene
{
public:
    PongScene();

    virtual void runThisTest();

    virtual void MainMenuCallback(CCObject* pSender);
};

class Ball;
class PongLayer : public CCLayer
{
	Ball*		m_ball;
	CCMutableArray<CCObject *> *m_paddles;
	CCPoint		m_ballStartingVelocity;
public:
	PongLayer();
	~PongLayer();

	void resetAndScoreBallForPlayer(int player);
	void doStep(ccTime delta);
};

#endif


code:
#include "TransitionsTest.h"
#include "../testResource.h"
#include "CCConfiguration.h"

#define TRANSITION_DURATION (1.2f)

class FadeWhiteTransition : public CCTransitionFade
{
public:
    static CCTransitionScene* transitionWithDuration(ccTime t, CCScene* s)
    {
        return CCTransitionFade::transitionWithDuration(t, s, ccWHITE);
    }
};

class FlipXLeftOver : public CCTransitionFlipX
{
public:
    static CCTransitionScene* transitionWithDuration(ccTime t, CCScene* s)
    {
        return CCTransitionFlipX::transitionWithDuration(t, s, kOrientationLeftOver);
    }
};

class FlipXRightOver : public CCTransitionFlipX
{
public:
    static CCTransitionScene* transitionWithDuration(ccTime t, CCScene* s)
    {
        return CCTransitionFlipX::transitionWithDuration(t, s, kOrientationRightOver);
    }
};

class FlipYUpOver : public CCTransitionFlipY
{
public:
    static CCTransitionScene* transitionWithDuration(ccTime t, CCScene* s)
    {
        return CCTransitionFlipY::transitionWithDuration(t, s, kOrientationUpOver);
    }
};

class FlipYDownOver : public CCTransitionFlipY
{
public:
    static CCTransitionScene* transitionWithDuration(ccTime t, CCScene* s)
    {
        return CCTransitionFlipY::transitionWithDuration(t, s, kOrientationDownOver);
    }
};

class FlipAngularLeftOver : public CCTransitionFlipAngular
{
public:
    static CCTransitionScene* transitionWithDuration(ccTime t, CCScene* s)
    {
        return CCTransitionFlipAngular::transitionWithDuration(t, s, kOrientationLeftOver);
    }
};

class FlipAngularRightOver : public CCTransitionFlipAngular
{
public:
    static CCTransitionScene* transitionWithDuration(ccTime t, CCScene* s)
    {
        return CCTransitionFlipAngular::transitionWithDuration(t, s, kOrientationRightOver);
    }
};

class ZoomFlipXLeftOver : public CCTransitionZoomFlipX
{
public:
    static CCTransitionScene* transitionWithDuration(ccTime t, CCScene* s)
    {
        return CCTransitionZoomFlipX::transitionWithDuration(t, s, kOrientationLeftOver);
    }
};

class ZoomFlipXRightOver : public CCTransitionZoomFlipX
{
public:
    static CCTransitionScene* transitionWithDuration(ccTime t, CCScene* s)
    {
        return CCTransitionZoomFlipX::transitionWithDuration(t, s, kOrientationRightOver);
    }
};

class ZoomFlipYUpOver : public CCTransitionZoomFlipY
{
public:
    static CCTransitionScene* transitionWithDuration(ccTime t, CCScene* s)
    {
        return CCTransitionZoomFlipY::transitionWithDuration(t, s, kOrientationUpOver);

    }
};

class ZoomFlipYDownOver : public CCTransitionZoomFlipY
{
public:
    static CCTransitionScene* transitionWithDuration(ccTime t, CCScene* s)
    {
        return CCTransitionZoomFlipY::transitionWithDuration(t, s, kOrientationDownOver);
    }
};

class ZoomFlipAngularLeftOver : public CCTransitionZoomFlipAngular
{
public:
    static CCTransitionScene* transitionWithDuration(ccTime t, CCScene* s)
    {
        return CCTransitionZoomFlipAngular::transitionWithDuration(t, s, kOrientationLeftOver);
    }
};

class ZoomFlipAngularRightOver : public CCTransitionZoomFlipAngular
{
public:
    static CCTransitionScene* transitionWithDuration(ccTime t, CCScene* s)
    {
        return CCTransitionZoomFlipAngular::transitionWithDuration(t, s, kOrientationRightOver);
    }
};

class PageTransitionForward : public CCTransitionPageTurn
{
public:
    static CCTransitionScene* transitionWithDuration(ccTime t, CCScene* s)
    {
        CCDirector::sharedDirector()->setDepthTest(true);
        return CCTransitionPageTurn::transitionWithDuration(t, s, false);
    }
};

class PageTransitionBackward : public CCTransitionPageTurn
{
public:
    static CCTransitionScene* transitionWithDuration(ccTime t, CCScene* s)
    {
        CCDirector::sharedDirector()->setDepthTest(true);
        return CCTransitionPageTurn::transitionWithDuration(t, s, true);
    }
};

#define MAX_LAYER	37

static std::string transitions[MAX_LAYER] = {
    "JumpZoomTransition",
    "FadeTransition",
    "FadeWhiteTransition",
    "FlipXLeftOver",
    "FlipXRightOver",
    "FlipYUpOver",
    "FlipYDownOver",
    "FlipAngularLeftOver",
    "FlipAngularRightOver",
    "ZoomFlipXLeftOver",
    "ZoomFlipXRightOver",
    "ZoomFlipYUpOver",
    "ZoomFlipYDownOver",
    "ZoomFlipAngularLeftOver",
    "ZoomFlipAngularRightOver",
    "ShrinkGrowTransition",
    "RotoZoomTransition",
    "MoveInLTransition",
    "MoveInRTransition",
    "MoveInTTransition",
    "MoveInBTransition",
    "SlideInLTransition",
    "SlideInRTransition",
    "SlideInTTransition",
    "SlideInBTransition",

    "CCTransitionCrossFade",
    "CCTransitionRadialCCW",
    "CCTransitionRadialCW",
    "PageTransitionForward",
    "PageTransitionBackward",
    "FadeTRTransition",
    "FadeBLTransition",
    "FadeUpTransition",
    "FadeDownTransition",
    "TurnOffTilesTransition",
    "SplitRowsTransition",
    "SplitColsTransition",
};
static int s_nSceneIdx = 0;

CCTransitionScene* createTransition(int nIndex, ccTime t, CCScene* s)
{
    // fix bug #486, without setDepthTest(false), FlipX,Y will flickers
    CCDirector::sharedDirector()->setDepthTest(false);

    switch(nIndex)
    {
    case 0: return CCTransitionJumpZoom::transitionWithDuration(t, s);
    case 1: return CCTransitionFade::transitionWithDuration(t, s);
    case 2: return FadeWhiteTransition::transitionWithDuration(t, s);
    case 3: return FlipXLeftOver::transitionWithDuration(t, s);
    case 4: return FlipXRightOver::transitionWithDuration(t, s);
    case 5: return FlipYUpOver::transitionWithDuration(t, s);
    case 6: return FlipYDownOver::transitionWithDuration(t, s);
    case 7: return FlipAngularLeftOver::transitionWithDuration(t, s);
    case 8: return FlipAngularRightOver::transitionWithDuration(t, s);
    case 9: return ZoomFlipXLeftOver::transitionWithDuration(t, s);
    case 10: return ZoomFlipXRightOver::transitionWithDuration(t, s);
    case 11: return ZoomFlipYUpOver::transitionWithDuration(t, s);
    case 12: return ZoomFlipYDownOver::transitionWithDuration(t, s);
    case 13: return ZoomFlipAngularLeftOver::transitionWithDuration(t, s);
    case 14: return ZoomFlipAngularRightOver::transitionWithDuration(t, s);
    case 15: return CCTransitionShrinkGrow::transitionWithDuration(t, s);
    case 16: return CCTransitionRotoZoom::transitionWithDuration(t, s);
    case 17: return CCTransitionMoveInL::transitionWithDuration(t, s);
    case 18: return CCTransitionMoveInR::transitionWithDuration(t, s);
    case 19: return CCTransitionMoveInT::transitionWithDuration(t, s);
    case 20: return CCTransitionMoveInB::transitionWithDuration(t, s);
    case 21: return CCTransitionSlideInL::transitionWithDuration(t, s);
    case 22: return CCTransitionSlideInR::transitionWithDuration(t, s);
    case 23: return CCTransitionSlideInT::transitionWithDuration(t, s);
    case 24: return CCTransitionSlideInB::transitionWithDuration(t, s);
    case 25:
		{
			if (CCConfiguration::sharedConfiguration()->getGlesVersion() <= GLES_VER_1_0)
			{
				CCMessageBox("The Opengl ES version is lower than 1.1, and TransitionCrossFade may not run correctly, it is ignored.", "Cocos2d-x Hint");
				return NULL;
			}
			else
			{
				return CCTransitionCrossFade::transitionWithDuration(t,s);
			}
		}
		break;
    case 26:
		{
			if (CCConfiguration::sharedConfiguration()->getGlesVersion() <= GLES_VER_1_0)
			{
				CCMessageBox("The Opengl ES version is lower than 1.1, and TransitionRadialCCW may not run correctly, it is ignored.", "Cocos2d-x Hint");
				return NULL;
			}
			else
			{
				return CCTransitionRadialCCW::transitionWithDuration(t,s);
			}
		}
		break;
    case 27:
		{
			if (CCConfiguration::sharedConfiguration()->getGlesVersion() <= GLES_VER_1_0)
			{
				CCMessageBox("The Opengl ES version is lower than 1.1, and TransitionRadialCW may not run correctly, it is ignored.", "Cocos2d-x Hint");
				return NULL;
			}
			else
			{
				return CCTransitionRadialCW::transitionWithDuration(t,s);
			}
		}
		break;
    case 28: return PageTransitionForward::transitionWithDuration(t, s);
    case 29: return PageTransitionBackward::transitionWithDuration(t, s);
    case 30: return CCTransitionFadeTR::transitionWithDuration(t, s);
    case 31: return CCTransitionFadeBL::transitionWithDuration(t, s);
    case 32: return CCTransitionFadeUp::transitionWithDuration(t, s);
    case 33: return CCTransitionFadeDown::transitionWithDuration(t, s);
    case 34: return CCTransitionTurnOffTiles::transitionWithDuration(t, s);
    case 35: return CCTransitionSplitRows::transitionWithDuration(t, s);
    case 36: return CCTransitionSplitCols::transitionWithDuration(t, s);
    default: break;
    }

    return NULL;
}

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

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

TestLayer1::TestLayer1(void)
{
    float x,y;

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

    CCSprite* bg1 = CCSprite::spriteWithFile(s_back1);
    bg1->setPosition( CCPointMake(size.width/2, size.height/2) );
    addChild(bg1, -1);

    CCLabelTTF* title = CCLabelTTF::labelWithString( (transitions[s_nSceneIdx]).c_str(), "Thonburi", 32 );
    addChild(title);
    title->setColor( ccc3(255,32,32) );
    title->setPosition( CCPointMake(x/2, y-100) );

    CCLabelTTF* label = CCLabelTTF::labelWithString("SCENE 1", "Marker Felt", 38);
    label->setColor( ccc3(16,16,255));
    label->setPosition( CCPointMake(x/2,y/2));
    addChild( label);

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

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

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

    addChild(menu, 1);

    schedule( schedule_selector(TestLayer1::step), 1.0f);
}

TestLayer1::~TestLayer1(void)
{

}

void TestLayer1::restartCallback(CCObject* pSender)
{
    CCScene* s = new TransitionsTestScene();

    CCLayer* pLayer = new TestLayer2();
    s->addChild(pLayer);

    CCScene* pScene = createTransition(s_nSceneIdx, TRANSITION_DURATION, s);
    s->release();
    pLayer->release();
    if (pScene)
    {
        CCDirector::sharedDirector()->replaceScene(pScene);
    }
}

void TestLayer1::nextCallback(CCObject* pSender)
{
    s_nSceneIdx++;
    s_nSceneIdx = s_nSceneIdx % MAX_LAYER;

    CCScene* s = new TransitionsTestScene();

    CCLayer* pLayer = new TestLayer2();
    s->addChild(pLayer);

    CCScene* pScene = createTransition(s_nSceneIdx, TRANSITION_DURATION, s);
    s->release();
    pLayer->release();
    if (pScene)
    {
        CCDirector::sharedDirector()->replaceScene(pScene);
    }
}

void TestLayer1::backCallback(CCObject* pSender)
{
    s_nSceneIdx--;
    int total = MAX_LAYER;
    if( s_nSceneIdx < 0 )
        s_nSceneIdx += total;

    CCScene* s = new TransitionsTestScene();

    CCLayer* pLayer = new TestLayer2();
    s->addChild(pLayer);

    CCScene* pScene = createTransition(s_nSceneIdx, TRANSITION_DURATION, s);
    s->release();
    pLayer->release();
    if (pScene)
    {
        CCDirector::sharedDirector()->replaceScene(pScene);
    }
}

void TestLayer1::step(ccTime dt)
{

}

TestLayer2::TestLayer2()
{
    float x,y;

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

    CCSprite* bg1 = CCSprite::spriteWithFile(s_back2);
    bg1->setPosition( CCPointMake(size.width/2, size.height/2) );
    addChild(bg1, -1);

    CCLabelTTF* title = CCLabelTTF::labelWithString((transitions[s_nSceneIdx]).c_str(), "Thonburi", 32 );
    addChild(title);
    title->setColor( ccc3(255,32,32) );
    title->setPosition( CCPointMake(x/2, y-100) );

    CCLabelTTF* label = CCLabelTTF::labelWithString("SCENE 2", "Marker Felt", 38);
    label->setColor( ccc3(16,16,255));
    label->setPosition( CCPointMake(x/2,y/2));
    addChild( label);

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

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

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

    addChild(menu, 1);

    schedule(schedule_selector(TestLayer2::step), 1.0f);
}

TestLayer2::~TestLayer2()
{

}

void TestLayer2::restartCallback(CCObject* pSender)
{
    CCScene* s = new TransitionsTestScene();

    CCLayer* pLayer = new TestLayer1();
    s->addChild(pLayer);

    CCScene* pScene = createTransition(s_nSceneIdx, TRANSITION_DURATION, s);
    s->release();
    pLayer->release();
    if (pScene)
    {
        CCDirector::sharedDirector()->replaceScene(pScene);
    }
}

void TestLayer2::nextCallback(CCObject* pSender)
{
    s_nSceneIdx++;
    s_nSceneIdx = s_nSceneIdx % MAX_LAYER;

    CCScene* s = new TransitionsTestScene();

    CCLayer* pLayer = new TestLayer1();
    s->addChild(pLayer);

    CCScene* pScene = createTransition(s_nSceneIdx, TRANSITION_DURATION, s);
    s->release();
    pLayer->release();
    if (pScene)
    {
        CCDirector::sharedDirector()->replaceScene(pScene);
    }
}

void TestLayer2::backCallback(CCObject* pSender)
{
    s_nSceneIdx--;
    int total = MAX_LAYER;
    if( s_nSceneIdx < 0 )
        s_nSceneIdx += total;

    CCScene* s = new TransitionsTestScene();

    CCLayer* pLayer = new TestLayer1();
    s->addChild(pLayer);

    CCScene* pScene = createTransition(s_nSceneIdx, TRANSITION_DURATION, s);
    s->release();
    pLayer->release();
    if (pScene)
    {
        CCDirector::sharedDirector()->replaceScene(pScene);
    }
}

void TestLayer2::step(ccTime dt)
{

}


code:
#ifndef _TRANSITIONS_TEST_H_
#define _TRANSITIONS_TEST_H_

#include "../testBasic.h"

using namespace cocos2d;

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

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

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

    void step(ccTime dt);
};

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

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

    void step(ccTime dt);
};

#endif


code:
// enable log
#define COCOS2D_DEBUG 1

#include "UserDefaultTest.h"
#include "stdio.h"
#include "stdlib.h"

UserDefaultTest::UserDefaultTest()
{
	CCSize s = CCDirector::sharedDirector()->getWinSize();
	CCLabelTTF* label = CCLabelTTF::labelWithString("CCUserDefault test see log", "Arial", 28);
	addChild(label, 0);
	label->setPosition( ccp(s.width/2, s.height-50) );

	doTest();
}

void UserDefaultTest::doTest()
{
	CCLOG("********************** init value ***********************");

	// set default value

	CCUserDefault::sharedUserDefault()->setStringForKey("string", "value1");
	CCUserDefault::sharedUserDefault()->setIntegerForKey("integer", 10);
	CCUserDefault::sharedUserDefault()->setFloatForKey("float", 2.3f);
	CCUserDefault::sharedUserDefault()->setDoubleForKey("double", 2.4);
	CCUserDefault::sharedUserDefault()->setBoolForKey("bool", true);

	// print value

	string ret = CCUserDefault::sharedUserDefault()->getStringForKey("string");
	CCLOG("string is %s", ret.c_str());

	double d = CCUserDefault::sharedUserDefault()->getDoubleForKey("double");
	CCLOG("double is %f", d);

	int i = CCUserDefault::sharedUserDefault()->getIntegerForKey("integer");
	CCLOG("integer is %d", i);

	float f = CCUserDefault::sharedUserDefault()->getFloatForKey("float");
	CCLOG("float is %f", f);

	bool b = CCUserDefault::sharedUserDefault()->getBoolForKey("bool");
	if (b)
	{
		CCLOG("bool is true");
	}
	else
	{
		CCLOG("bool is false");
	}

	//CCUserDefault::sharedUserDefault()->flush();

    CCLOG("********************** after change value ***********************");

	// change the value

	CCUserDefault::sharedUserDefault()->setStringForKey("string", "value2");
	CCUserDefault::sharedUserDefault()->setIntegerForKey("integer", 11);
	CCUserDefault::sharedUserDefault()->setFloatForKey("float", 2.5f);
	CCUserDefault::sharedUserDefault()->setDoubleForKey("double", 2.6);
	CCUserDefault::sharedUserDefault()->setBoolForKey("bool", false);

	CCUserDefault::sharedUserDefault()->flush();

	// print value

	ret = CCUserDefault::sharedUserDefault()->getStringForKey("string");
	CCLOG("string is %s", ret.c_str());

	d = CCUserDefault::sharedUserDefault()->getDoubleForKey("double");
	CCLOG("double is %f", d);

	i = CCUserDefault::sharedUserDefault()->getIntegerForKey("integer");
	CCLOG("integer is %d", i);

	f = CCUserDefault::sharedUserDefault()->getFloatForKey("float");
	CCLOG("float is %f", f);

	b = CCUserDefault::sharedUserDefault()->getBoolForKey("bool");
	if (b)
	{
		CCLOG("bool is true");
	}
	else
	{
		CCLOG("bool is false");
	}
}

UserDefaultTest::~UserDefaultTest()
{
}

void UserDefaultTestScene::runThisTest()
{
    CCLayer* pLayer = new UserDefaultTest();
    addChild(pLayer);

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


code:
#ifndef _USERDEFAULT_TEST_H_
#define _USERDEFAULT_TEST_H_

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

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

private:
	void doTest();
};

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

#endif // _USERDEFAULT_TEST_H_


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

#define MAX_LAYER	1

static int sceneIdx = -1;

CCLayer* nextZwoptexTest();
CCLayer* backZwoptexTest();
CCLayer* restartZwoptexTest();

CCLayer* createZwoptexLayer(int nIndex)
{
    switch(nIndex)
    {
    case 0: return new ZwoptexGenericTest();
    }

    return NULL;
}

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

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

    return pLayer;
}

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

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

    return pLayer;
}

CCLayer* restartZwoptexTest()
{
    CCLayer* pLayer = createZwoptexLayer(sceneIdx);
    pLayer->autorelease();

    return pLayer;
}

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

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

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

    std::string strSubTitle = subtitle();
	if (strSubTitle.length() > 0)
    {
        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(ZwoptexTest::backCallback) );
    CCMenuItemImage *item2 = CCMenuItemImage::itemFromNormalImage(s_pPathR1, s_pPathR2, this, menu_selector(ZwoptexTest::restartCallback) );
    CCMenuItemImage *item3 = CCMenuItemImage::itemFromNormalImage(s_pPathF1, s_pPathF2, this, menu_selector(ZwoptexTest::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 ZwoptexTest::restartCallback(CCObject* pSender)
{
    CCScene *s = ZwoptexTestScene::node();
	s->addChild(restartZwoptexTest());
    CCDirector::sharedDirector()->replaceScene(s);
}

void ZwoptexTest::nextCallback(CCObject* pSender)
{
	CCScene *s = ZwoptexTestScene::node();
	s->addChild(nextZwoptexTest());
    CCDirector::sharedDirector()->replaceScene(s);
}

void ZwoptexTest::backCallback(CCObject* pSender)
{
	CCScene *s = ZwoptexTestScene::node();
	s->addChild(backZwoptexTest());
    CCDirector::sharedDirector()->replaceScene(s);
}

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

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

//------------------------------------------------------------------
//
// ZwoptexGenericTest
//
//------------------------------------------------------------------
void ZwoptexGenericTest::onEnter()
{
    ZwoptexTest::onEnter();

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

    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("zwoptex/grossini.plist");
    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("zwoptex/grossini-generic.plist");

    CCLayerColor *layer1 = CCLayerColor::layerWithColorWidthHeight(ccc4f(255, 0, 0, 255), 85, 121);
	layer1->setPosition(ccp(s.width/2-80 - (85.0f * 0.5f), s.height/2 - (121.0f * 0.5f)));
	addChild(layer1);

    sprite1 = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("grossini_dance_01.png"));
	sprite1->setPosition(ccp( s.width/2-80, s.height/2));
	addChild(sprite1);

	sprite1->setFlipX(false);
	sprite1->setFlipY(false);

    CCLayerColor *layer2 = CCLayerColor::layerWithColorWidthHeight(ccc4f(255, 0, 0, 255), 85, 121);
	layer2->setPosition(ccp(s.width/2+80 - (85.0f * 0.5f), s.height/2 - (121.0f * 0.5f)));
	addChild(layer2);

    sprite2 = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("grossini_dance_generic_01.png"));
	sprite2->setPosition(ccp( s.width/2 + 80, s.height/2));
	addChild(sprite2);

    sprite2->setFlipX(false);
    sprite2->setFlipY(false);

    schedule(schedule_selector(ZwoptexGenericTest::startIn05Secs), 1.0f);

	sprite1->retain();
	sprite2->retain();

	counter = 0;
}

void ZwoptexGenericTest::startIn05Secs(ccTime dt)
{
	unschedule(schedule_selector(ZwoptexGenericTest::startIn05Secs));
	schedule(schedule_selector(ZwoptexGenericTest::flipSprites), 0.5f);
}

static int spriteFrameIndex = 0;
void ZwoptexGenericTest::flipSprites(ccTime dt)
{
	counter++;

	bool fx = false;
	bool fy = false;
	int i = counter % 4;

	switch ( i )
    {
		case 0:
			fx = false;
			fy = false;
			break;
		case 1:
			fx = true;
			fy = false;
			break;
		case 2:
			fx = false;
			fy = true;
			break;
		case 3:
			fx = true;
			fy = true;
			break;
	}

	sprite1->setFlipX(fx);
    sprite2->setFlipX(fx);
    sprite1->setFlipY(fy);
    sprite2->setFlipY(fy);

	if(++spriteFrameIndex > 14)
    {
		spriteFrameIndex = 1;
	}

    char str1[32] = {0};
    char str2[32] = {0};
    sprintf(str1, "grossini_dance_%02d.png", spriteFrameIndex);
    sprintf(str2, "grossini_dance_generic_%02d.png", spriteFrameIndex);
    sprite1->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(str1));
    sprite2->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(str2));
}

ZwoptexGenericTest::~ZwoptexGenericTest()
{
    sprite1->release();
    sprite2->release();
    CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache();
    cache->removeSpriteFramesFromFile("zwoptex/grossini.plist");
    cache->removeSpriteFramesFromFile("zwoptex/grossini-generic.plist");
}

std::string ZwoptexGenericTest::title()
{
	return "Zwoptex Tests";
}

std::string ZwoptexGenericTest::subtitle()
{
	return "Coordinate Formats, Rotation, Trimming, flipX/Y";
}

void ZwoptexTestScene::runThisTest()
{
    CCLayer* pLayer = nextZwoptexTest();
    addChild(pLayer);

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


code:
#ifndef __ZWOPTEX_TEST_H__
#define __ZWOPTEX_TEST_H__

#include "../testBasic.h"

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

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

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

class ZwoptexGenericTest : public ZwoptexTest
{
public:
    ~ZwoptexGenericTest();
    virtual void onEnter();
    void flipSprites(ccTime dt);
    void startIn05Secs(ccTime dt);

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

protected:
	CCSprite * sprite1;
    CCSprite * sprite2;
	int counter;
};

class ZwoptexTestScene : public TestScene
{
public:
    virtual void runThisTest();

    SCENE_NODE_FUNC(ZwoptexTestScene);
};

#endif // __ZWOPTEX_TEST_H__


code:
#include "controller.h"
#include "testResource.h"
#include "tests.h"

#define LINE_SPACE          40

static CCPoint s_tCurPos = CCPointZero;

static TestScene* CreateTestScene(int nIdx)
{
    CCDirector::sharedDirector()->purgeCachedData();

    TestScene* pScene = NULL;

    switch (nIdx)
    {
    case TEST_ACTIONS:
        pScene = new ActionsTestScene(); break;
    case TEST_TRANSITIONS:
        pScene = new TransitionsTestScene(); break;
    case TEST_PROGRESS_ACTIONS:
        pScene = new ProgressActionsTestScene(); break;
    case TEST_EFFECTS:
        pScene = new EffectTestScene(); break;
    case TEST_CLICK_AND_MOVE:
        pScene = new ClickAndMoveTestScene(); break;
    case TEST_ROTATE_WORLD:
        pScene = new RotateWorldTestScene(); break;
    case TEST_PARTICLE:
        pScene = new ParticleTestScene(); break;
    case TEST_EASE_ACTIONS:
        pScene = new EaseActionsTestScene(); break;
    case TEST_MOTION_STREAK:
        pScene = new MotionStreakTestScene(); break;
    case TEST_DRAW_PRIMITIVES:
        pScene = new DrawPrimitivesTestScene(); break;
    case TEST_COCOSNODE:
        pScene = new CocosNodeTestScene(); break;
    case TEST_TOUCHES:
        pScene = new PongScene(); break;
    case TEST_MENU:
        pScene = new MenuTestScene(); break;
    case TEST_ACTION_MANAGER:
        pScene = new ActionManagerTestScene(); break;
    case TEST_LAYER:
        pScene = new LayerTestScene(); break;
    case TEST_SCENE:
        pScene = new SceneTestScene(); break;
    case TEST_PARALLAX:
        pScene = new ParallaxTestScene(); break;
    case TEST_TILE_MAP:
        pScene = new TileMapTestScene(); break;
    case TEST_INTERVAL:
        pScene = new IntervalTestScene(); break;
    case TEST_CHIPMUNK:
#if (CC_TARGET_PLATFORM != CC_PLATFORM_MARMALADE)
        pScene = new ChipmunkTestScene(); break;
#else
#ifdef MARMALADEUSECHIPMUNK
#if	(MARMALADEUSECHIPMUNK == 1)
        pScene = new ChipmunkTestScene();
#endif
		break;
#endif
#endif
    case TEST_LABEL:
        pScene = new AtlasTestScene(); break;
    case TEST_TEXT_INPUT:
        pScene = new TextInputTestScene(); break;
    case TEST_SPRITE:
        pScene = new SpriteTestScene(); break;
    case TEST_SCHEDULER:
        pScene = new SchedulerTestScene(); break;
    case TEST_RENDERTEXTURE:
        pScene = new RenderTextureScene(); break;
    case TEST_TEXTURE2D:
        pScene = new TextureTestScene(); break;
    case TEST_BOX2D:
        pScene = new Box2DTestScene(); break;
    case TEST_BOX2DBED:
        pScene = new Box2dTestBedScene(); break;
    case TEST_EFFECT_ADVANCE:
        pScene = new EffectAdvanceScene(); break;
    case TEST_HIRES:
        pScene = new HiResTestScene(); break;
	case TEST_ACCELEROMRTER:
        pScene = new AccelerometerTestScene(); break;
#if (CC_TARGET_PLATFORM != CC_PLATFORM_BADA)
    case TEST_KEYPAD:
        pScene = new KeypadTestScene(); break;
#endif
	case TEST_COCOSDENSHION:
		pScene = new CocosDenshionTestScene(); break;
    case TEST_PERFORMANCE:
        pScene = new PerformanceTestScene(); break;
    case TEST_ZWOPTEX:
        pScene = new ZwoptexTestScene(); break;
#if (CC_TARGET_PLATFORM != CC_PLATFORM_MARMALADE)
// bada don't support libcurl
#if (CC_TARGET_PLATFORM != CC_PLATFORM_BADA)
#if (CC_TARGET_PLATFORM != CC_PLATFORM_QT)
	case TEST_CURL:
		pScene = new CurlTestScene(); break;
#endif
#endif
#endif
	case TEST_USERDEFAULT:
		pScene = new UserDefaultTestScene(); break;
    case TEST_DIRECTOR:
        pScene = new DirectorTestScene(); break;
    case TEST_BUGS:
        pScene = new BugsTestScene(); break;
	case TEST_FONTS:
		pScene = new FontTestScene(); break;
	case TEST_CURRENT_LANGUAGE:
		pScene = new CurrentLanguageTestScene(); break;
#if (CC_TARGET_PLATFORM != CC_PLATFORM_MARMALADE)
	case TEST_TEXTURECACHE: pScene = new TextureCacheTestScene(); break;
#endif
    case TEST_EXTENSIONS:
        {
            pScene = new ExtensionsTestScene();
        }
        break;
    default:
        break;
    }

    return pScene;
}

TestController::TestController()
: m_tBeginPos(CCPointZero)
{
    // add close menu
    CCMenuItemImage *pCloseItem = CCMenuItemImage::itemFromNormalImage(s_pPathClose, s_pPathClose, this, menu_selector(TestController::closeCallback) );
    CCMenu* pMenu =CCMenu::menuWithItems(pCloseItem, NULL);
    CCSize s = CCDirector::sharedDirector()->getWinSize();

    pMenu->setPosition( CCPointZero );
    pCloseItem->setPosition(CCPointMake( s.width - 30, s.height - 30));

    // add menu items for tests
    m_pItemMenu = CCMenu::menuWithItems(NULL);
    for (int i = 0; i < TESTS_COUNT; ++i)
    {
// #if (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE)
// 		CCLabelBMFont* label = CCLabelBMFont::labelWithString(g_aTestNames[i].c_str(),  "fonts/arial16.fnt");
// #else
        CCLabelTTF* label = CCLabelTTF::labelWithString(g_aTestNames[i].c_str(), "Arial", 24);
// #endif
        CCMenuItemLabel* pMenuItem = CCMenuItemLabel::itemWithLabel(label, this, menu_selector(TestController::menuCallback));

        m_pItemMenu->addChild(pMenuItem, i + 10000);
        pMenuItem->setPosition( CCPointMake( s.width / 2, (s.height - (i + 1) * LINE_SPACE) ));
    }

    m_pItemMenu->setContentSize(CCSizeMake(s.width, (TESTS_COUNT + 1) * (LINE_SPACE)));
    m_pItemMenu->setPosition(s_tCurPos);
    addChild(m_pItemMenu);

    setIsTouchEnabled(true);

    addChild(pMenu, 1);
}

TestController::~TestController()
{
}

void TestController::menuCallback(CCObject * pSender)
{
    // get the userdata, it's the index of the menu item clicked
    CCMenuItem* pMenuItem = (CCMenuItem *)(pSender);
    int nIdx = pMenuItem->getZOrder() - 10000;

    // create the test scene and run it
    TestScene* pScene = CreateTestScene(nIdx);
    if (pScene)
    {
        pScene->runThisTest();
        pScene->release();
    }
}

void TestController::closeCallback(CCObject * pSender)
{
    CCDirector::sharedDirector()->end();
}

void TestController::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
{
    CCSetIterator it = pTouches->begin();
    CCTouch* touch = (CCTouch*)(*it);

    m_tBeginPos = touch->locationInView();
    m_tBeginPos = CCDirector::sharedDirector()->convertToGL( m_tBeginPos );
}

void TestController::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent)
{
    CCSetIterator it = pTouches->begin();
    CCTouch* touch = (CCTouch*)(*it);

    CCPoint touchLocation = touch->locationInView();
    touchLocation = CCDirector::sharedDirector()->convertToGL( touchLocation );
    float nMoveY = touchLocation.y - m_tBeginPos.y;

    CCPoint curPos  = m_pItemMenu->getPosition();
    CCPoint nextPos = ccp(curPos.x, curPos.y + nMoveY);
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    if (nextPos.y < 0.0f)
    {
        m_pItemMenu->setPosition(CCPointZero);
        return;
    }

    if (nextPos.y > ((TESTS_COUNT + 1)* LINE_SPACE - winSize.height))
    {
        m_pItemMenu->setPosition(ccp(0, ((TESTS_COUNT + 1)* LINE_SPACE - winSize.height)));
        return;
    }

    m_pItemMenu->setPosition(nextPos);
    m_tBeginPos = touchLocation;
    s_tCurPos   = nextPos;
}


code:
#ifndef _CONTROLLER_H_
#define _CONTROLLER_H_

#include "cocos2d.h"

using namespace cocos2d;

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

    void menuCallback(CCObject * pSender);
    void closeCallback(CCObject * pSender);

    virtual void ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent);
    virtual void ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent);

private:
    CCPoint m_tBeginPos;
    CCMenu* m_pItemMenu;
};

#endif


code:
#include "testBasic.h"
#include "controller.h"

TestScene::TestScene(bool bPortrait)
:m_bPortrait(bPortrait)
{
    if (m_bPortrait)
    {
        CCDirector::sharedDirector()->setDeviceOrientation(CCDeviceOrientationLandscapeRight);
    }

    CCScene::init();
}

void TestScene::onEnter()
{
    CCScene::onEnter();

    //add the menu item for back to main menu
//#if (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE)
//    CCLabelBMFont* label = CCLabelBMFont::labelWithString("MainMenu",  "fonts/arial16.fnt");
//#else
    CCLabelTTF* label = CCLabelTTF::labelWithString("MainMenu", "Arial", 20);
//#endif
    CCMenuItemLabel* pMenuItem = CCMenuItemLabel::itemWithLabel(label, this, menu_selector(TestScene::MainMenuCallback));

    CCMenu* pMenu =CCMenu::menuWithItems(pMenuItem, NULL);
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    pMenu->setPosition( CCPointZero );
    pMenuItem->setPosition( CCPointMake( s.width - 50, 25) );

    addChild(pMenu, 1);
}

void TestScene::MainMenuCallback(CCObject* pSender)
{
    CCScene* pScene = CCScene::node();
    CCLayer* pLayer = new TestController();
    pLayer->autorelease();

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


code:
#ifndef _TEST_BASIC_H_
#define _TEST_BASIC_H_

#include "cocos2d.h"

using namespace cocos2d;

class TestScene : public CCScene
{
public:
    TestScene(bool bPortrait = false);
    virtual void onEnter();

    virtual void runThisTest() = 0;

    // The CallBack for back to the main menu scene
    virtual void MainMenuCallback(CCObject* pSender);

protected:
    bool m_bPortrait; // indicate if this test case requires portrait mode
};

#endif


code:
#ifndef _TEST_RESOURCE_H_
#define _TEST_RESOURCE_H_

static const char s_pPathGrossini[]       = "Images/grossini.png";
static const char s_pPathSister1[]        = "Images/grossinis_sister1.png";
static const char s_pPathSister2[]        = "Images/grossinis_sister2.png";
static const char s_pPathB1[]             = "Images/b1.png";
static const char s_pPathB2[]             = "Images/b2.png";
static const char s_pPathR1[]             = "Images/r1.png";
static const char s_pPathR2[]             = "Images/r2.png";
static const char s_pPathF1[]             = "Images/f1.png";
static const char s_pPathF2[]             = "Images/f2.png";
static const char s_pPathBlock[]          = "Images/blocks.png";
static const char s_back[]                = "Images/background.png";
static const char s_back1[]               = "Images/background1.png";
static const char s_back2[]               = "Images/background2.png";
static const char s_back3[]               = "Images/background3.png";
static const char s_stars1[]              = "Images/stars.png";
static const char s_stars2[]              = "Images/stars2.png";
static const char s_fire[]                = "Images/fire.png";
static const char s_snow[]                = "Images/snow.png";
static const char s_streak[]              = "Images/streak.png";
static const char s_PlayNormal[]          = "Images/btn-play-normal.png";
static const char s_PlaySelect[]          = "Images/btn-play-selected.png";
static const char s_AboutNormal[]         = "Images/btn-about-normal.png";
static const char s_AboutSelect[]         = "Images/btn-about-selected.png";
static const char s_HighNormal[]          = "Images/btn-highscores-normal.png";
static const char s_HighSelect[]          = "Images/btn-highscores-selected.png";
static const char s_Ball[]                = "Images/ball.png";
static const char s_Paddle[]              = "Images/paddle.png";
static const char s_pPathClose[]          = "Images/close.png";
static const char s_MenuItem[]            = "Images/menuitemsprite.png";
static const char s_SendScore[]           = "Images/SendScoreButton.png";
static const char s_PressSendScore[]      = "Images/SendScoreButtonPressed.png";
static const char s_Power[]               = "Images/powered.png";
static const char s_AtlasTest[]           = "Images/atlastest.png";

// tilemaps resource
static const char s_TilesPng[]            = "TileMaps/tiles.png";
static const char s_LevelMapTga[]         = "TileMaps/levelmap.tga";

#endif


code:
#ifndef _TESTS_H_
#define _TESTS_H_

#include "ActionsTest/ActionsTest.h"
#include "TransitionsTest/TransitionsTest.h"
#include "ProgressActionsTest/ProgressActionsTest.h"
#include "EffectsTest/EffectsTest.h"
#include "ClickAndMoveTest/ClickAndMoveTest.h"
#include "RotateWorldTest/RotateWorldTest.h"
#include "ParticleTest/ParticleTest.h"
#include "EaseActionsTest/EaseActionsTest.h"
#include "MotionStreakTest/MotionStreakTest.h"
#include "DrawPrimitivesTest/DrawPrimitivesTest.h"
#include "CocosNodeTest/CocosNodeTest.h"
#include "TouchesTest/TouchesTest.h"
#include "MenuTest/MenuTest.h"
#include "ActionManagerTest/ActionManagerTest.h"
#include "LayerTest/LayerTest.h"
#include "SceneTest/SceneTest.h"
#include "ParallaxTest/ParallaxTest.h"
#include "TileMapTest/TileMapTest.h"
#include "IntervalTest/IntervalTest.h"
#include "LabelTest/LabelTest.h"
// havn't implement on marmalade
//#if (CC_TARGET_PLATFORM != CC_PLATFORM_MARMALADE)
#include "TextInputTest/TextInputTest.h"
//#endif
#include "SpriteTest/SpriteTest.h"
#include "SchedulerTest/SchedulerTest.h"
#include "RenderTextureTest/RenderTextureTest.h"
#include "Box2DTest/Box2dTest.h"
#include "Box2DTestBed/Box2dView.h"
#include "EffectsAdvancedTest/EffectsAdvancedTest.h"
#include "HiResTest/HiResTest.h"
#include "AccelerometerTest/AccelerometerTest.h"
#include "KeypadTest/KeypadTest.h"
#include "PerformanceTest/PerformanceTest.h"
#include "ZwoptexTest/ZwoptexTest.h"
#include "CocosDenshionTest/CocosDenshionTest.h"
#include "CurlTest/CurlTest.h"
#include "UserDefaultTest/UserDefaultTest.h"
#include "DirectorTest/DirectorTest.h"
#include "BugsTest/BugsTest.h"
#include "Texture2dTest/Texture2dTest.h"
#include "FontTest/FontTest.h"
#include "CurrentLanguageTest/CurrentLanguageTest.h"
#include "TextureCacheTest/TextureCacheTest.h"

#if (CC_TARGET_PLATFORM != CC_PLATFORM_MARMALADE)
	#include "ChipmunkTest/cocos2dChipmunkDemo.h"
#else
#ifdef MARMALADEUSECHIPMUNK
#if	(MARMALADEUSECHIPMUNK == 1)
	#include "ChipmunkTest/cocos2dChipmunkDemo.h"
#endif
#endif
#endif // (CC_TARGET_PLATFORM != CC_PLATFORM_MARMALADE)

#include "ExtensionsTest/ExtensionsTest.h"

enum
{
    TEST_ACTIONS = 0,
    TEST_TRANSITIONS,
    TEST_PROGRESS_ACTIONS,
    TEST_EFFECTS,
    TEST_CLICK_AND_MOVE,
    TEST_ROTATE_WORLD,
    TEST_PARTICLE,
    TEST_EASE_ACTIONS,
    TEST_MOTION_STREAK,
    TEST_DRAW_PRIMITIVES,
    TEST_COCOSNODE,
    TEST_TOUCHES,
    TEST_MENU,
    TEST_ACTION_MANAGER,
    TEST_LAYER,
    TEST_SCENE,
    TEST_PARALLAX,
    TEST_TILE_MAP,
    TEST_INTERVAL,
    TEST_CHIPMUNK,
    TEST_LABEL,
    TEST_TEXT_INPUT,
    TEST_SPRITE,
    TEST_SCHEDULER,
    TEST_RENDERTEXTURE,
    TEST_TEXTURE2D,
    TEST_BOX2D,
    TEST_BOX2DBED,
    TEST_EFFECT_ADVANCE,
    TEST_HIRES,
    TEST_ACCELEROMRTER,
    TEST_KEYPAD,
	TEST_COCOSDENSHION,
    TEST_PERFORMANCE,
    TEST_ZWOPTEX,
	TEST_CURL,
	TEST_USERDEFAULT,
    TEST_DIRECTOR,
    TEST_BUGS,
	TEST_FONTS,
	TEST_CURRENT_LANGUAGE,
	TEST_TEXTURECACHE,
    TEST_EXTENSIONS,
    TESTS_COUNT,
};

const std::string g_aTestNames[TESTS_COUNT] = {
    "ActionsTest",
    "TransitionsTest",
    "ProgressActionsTest",
    "EffectsTest",
    "ClickAndMoveTest",
    "RotateWorldTest",
    "ParticleTest",
    "EaseActionsTest",
    "MotionStreakTest",
    "DrawPrimitivesTest",
    "CocosNodeTest",
    "TouchesTest",
    "MenuTest",
    "ActionManagerTest",
    "LayerTest",
    "SceneTest",
    "ParallaxTest",
    "TileMapTest",
    "IntervalTest",
    "ChipmunkTest",
    "LabelTest",
    "TextInputTest",
    "SpriteTest",
    "SchdulerTest",
    "RenderTextureTest",
    "Texture2DTest",
    "Box2dTest",
    "Box2dTestBed",
    "EffectAdvancedTest",
    "HiResTest",
    "Accelerometer",
    "KeypadTest",
	"CocosDenshionTest",
    "PerformanceTest",
    "ZwoptexTest",
	"CurlTest",
	"UserDefaultTest",
    "DirectorTest",
    "BugsTest",
	"FontTest",
	"CurrentLanguageTest",
	"TextureCacheTest",
    "ExtensionsTest"
};

#endif


code:
This tool can be used to generate a 'jumping off point' for creating cross platform mobile games using the LUA bindings
with Cocos2d-x.

Usage is simple:

  'ant'

You will be asked 3 questions.

1) The path to your NDK (e.g. /cygdrive/c/my_first_ndk or /usr/bin/my_first_ndk )
2) The 'Name' of your project (e.g. AwesomeMegaDeath)
3) The 'Pakage' of your project (e.g. org.my)

The script will then generate a folder with the name of your project ('AwesomeMegaDeath') in the top-level of the Cocos2d-x downloadable (i.e. a sibling of HellowWorld.)  And you should be able to use this project straight away from Visual Studio, Xcode and Eclipse (Please note with eclipse you will also need to execute the build_native.sh script in the android sub-folder.)


code:
<project name="Cocos2d-xToLua" default="create-lua-project" basedir=".">
    <description>
        Utilises an existing template project(s) to create a brand new cross-platform
        lua project.
    </description>
    <property name="templateSrc" value="./template" />
    <property name="destRoot" value="../.." />
    <property name="template.project.name" value="LuaProjectTemplate" />
    <property name="template.project.namespace" value="org.my" />

  <target name="create-lua-project">
    <input message="Please enter project name" addproperty="project.name" />
    <input message="Please enter project namespace" addproperty="project.namespace" />
    <input message="Please enter the full path to your NDK" addproperty="ndk.location" />

    <property name="destDir" value="${destRoot}/${project.name}" />

    <input message="Will create a project '${project.namespace}.${project.name} into ${destDir},  continue (y/n)?"
        validargs="y,n"
        addproperty="do.continue"
      />
      <condition property="do.abort">
        <equals arg1="n" arg2="${do.continue}"/>
      </condition>
      <fail if="do.abort">Build aborted by user.</fail>

      <!-- If we get here we know we we're good to go! -->
      <delete dir="${destDir}"/>

      <echo message="Copying template files..." />
      <copy todir="${destDir}">
         <fileset dir="${templateSrc}" />
       </copy>
       <echo message="Renaming project files"/>
       <move todir="${destDir}" includeemptydirs="true">
          <fileset dir="${destDir}" />
          <regexpmapper from="^(.*)${template.project.name}(.*)$$" to="\1${project.name}\2"/>
        </move>

        <echo message="Updating project content"/>
        <replace token= "${template.project.name}" value= "${project.name}" >
          <fileset dir="${destDir}" defaultexcludes="false" excludes=".git"/>
        </replace>
        <replace token= "${template.project.namespace}" value= "${project.namespace}" >
          <fileset dir="${destDir}"/>
        </replace>

        <!-- Fix-up the Java entry point -->
        <move todir="${destDir}/android/src/${project.namespace}.${project.name}.java" file="${destDir}/android/src/${project.name}.java" />
        <pathconvert property="packageAsPath">
              <path path="${destDir}/android/src/${project.namespace}.${project.name}.java"/>
              <unpackagemapper from="*${project.name}.java" to="*"/>
        </pathconvert>
        <move file="${destDir}/android/src/${project.namespace}.${project.name}.java" tofile= "${packageAsPath}" />

        <path id="cocos2dxLocation"  path="{basedir}/../../.." />
        <property name="cocos2dxLocation.path" refid="cocos2dxLocation"/>
        <!-- Point the android build_native script at your NDK locations -->
        <replaceregexp file="${destDir}/android/build_native.sh"
                       match="COCOS2DX_ROOT=.*$$"
                       replace="COCOS2DX_ROOT=${cocos2dxLocation.path}"
                       byline="true"/>
        <replaceregexp file="${destDir}/android/build_native.sh"
                       match="ANDROID_NDK_ROOT=.*$$"
                       replace="ANDROID_NDK_ROOT=${ndk.location}"
                       byline="true"/>

        <chmod file="${destDir}/android/build_native.sh" perm="+x"/>
        <copy file="${templateSrc}/.gitignore" tofile="${destDir}/.gitignore" />
  </target>
</project>


code:
/android/bin
/android/gen
/android/libs
/android/obj
/android/assets

# xcode noise.
/ios/build/*
*.pbxuser
*.mode1v3
xcuserdata/

# osx noise
.DS_Store
profile