axmol/samples/Cpp/TestCpp/Classes/TileMapTest/TileMapTest.cpp

1561 lines
41 KiB
C++
Raw Normal View History

2010-11-18 14:50:28 +08:00
#include "TileMapTest.h"
#include "../testResource.h"
2010-09-01 17:30:51 +08:00
enum
{
kTagTileMap = 1,
2010-11-18 14:50:28 +08:00
};
Layer* nextTileMapAction();
Layer* backTileMapAction();
Layer* restartTileMapAction();
2011-07-08 15:57:46 +08:00
2010-09-01 17:30:51 +08:00
//------------------------------------------------------------------
//
// TileMapTest
//
//------------------------------------------------------------------
2010-11-18 14:50:28 +08:00
TileMapTest::TileMapTest()
{
TileMapAtlas* map = TileMapAtlas::create(s_TilesPng, s_LevelMapTga, 16, 16);
// Convert it to "alias" (GL_LINEAR filtering)
map->getTexture()->setAntiAliasTexParameters();
Size CC_UNUSED s = map->getContentSize();
CCLOG("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);
2013-07-12 14:11:55 +08:00
map->setAnchorPoint( Point(0, 0.5f) );
2011-02-23 16:47:25 +08:00
ScaleBy *scale = ScaleBy::create(4, 0.8f);
ActionInterval *scaleBack = scale->reverse();
Sequence* seq = Sequence::create(scale, scaleBack, NULL);
map->runAction(RepeatForever::create(seq));
2010-11-18 14:50:28 +08:00
}
2010-09-01 17:30:51 +08:00
std::string TileMapTest::title()
{
return "TileMapAtlas";
2010-09-01 17:30:51 +08:00
}
2010-11-18 14:50:28 +08:00
2010-09-01 17:30:51 +08:00
//------------------------------------------------------------------
//
// TileMapEditTest
//
//------------------------------------------------------------------
2010-11-18 14:50:28 +08:00
TileMapEditTest::TileMapEditTest()
{
TileMapAtlas* map = TileMapAtlas::create(s_TilesPng, s_LevelMapTga, 16, 16);
// Create an Aliased Atlas
map->getTexture()->setAliasTexParameters();
Size CC_UNUSED s = map->getContentSize();
CCLOG("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);
addChild(map, 0, kTagTileMap);
2013-07-12 14:11:55 +08:00
map->setAnchorPoint( Point(0, 0) );
map->setPosition( Point(-20,-200) );
2010-11-18 14:50:28 +08:00
}
2010-09-01 17:30:51 +08:00
2012-06-08 13:55:28 +08:00
void TileMapEditTest::updateMap(float dt)
2010-09-01 17:30:51 +08:00
{
// 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
TileMapAtlas* tilemap = (TileMapAtlas*) 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++) {
// Color3B c =[tilemap tileAt:Size(x,y));
// if( c.r != 0 ) {
// ////----CCLOG("%d,%d = %d", x,y,c.r);
// }
// }
// }
// NEW since v0.7
Color3B c = tilemap->getTileAt(Point(13,21));
c.r++;
c.r %= 50;
if( c.r==0)
c.r=1;
// NEW since v0.7
2013-07-12 14:11:55 +08:00
tilemap->setTile(c, Point(13,21) );
2010-09-01 17:30:51 +08:00
}
std::string TileMapEditTest::title()
{
return "Editable TileMapAtlas";
2010-09-01 17:30:51 +08:00
}
2010-11-18 14:50:28 +08:00
2010-09-01 17:30:51 +08:00
//------------------------------------------------------------------
//
// TMXOrthoTest
//
//------------------------------------------------------------------
2010-11-18 14:50:28 +08:00
TMXOrthoTest::TMXOrthoTest()
{
//
// Test orthogonal with 3d camera and anti-alias textures
//
// it should not flicker. No artifacts should appear
//
//CCLayerColor* color = LayerColor::create( Color4B(64,64,64,255) );
//addChild(color, -1);
TMXTiledMap* map = TMXTiledMap::create("TileMaps/orthogonal-test2.tmx");
addChild(map, 0, kTagTileMap);
Size CC_UNUSED s = map->getContentSize();
CCLOG("ContentSize: %f, %f", s.width,s.height);
Array * pChildrenArray = map->getChildren();
SpriteBatchNode* child = NULL;
Object* pObject = NULL;
CCARRAY_FOREACH(pChildrenArray, pObject)
{
child = static_cast<SpriteBatchNode*>(pObject);
2010-09-01 17:30:51 +08:00
if(!child)
break;
2010-09-01 17:30:51 +08:00
child->getTexture()->setAntiAliasTexParameters();
}
2010-09-01 17:30:51 +08:00
float x, y, z;
map->getCamera()->getEyeXYZ(&x, &y, &z);
map->getCamera()->setEyeXYZ(x-200, y, z+300);
2010-11-18 14:50:28 +08:00
}
2010-09-01 17:30:51 +08:00
void TMXOrthoTest::onEnter()
{
TileDemo::onEnter();
2010-09-01 17:30:51 +08:00
Director::getInstance()->setProjection(kDirectorProjection3D);
2010-09-01 17:30:51 +08:00
}
void TMXOrthoTest::onExit()
{
Director::getInstance()->setProjection(kDirectorProjection2D);
TileDemo::onExit();
2010-11-18 14:50:28 +08:00
}
2010-09-01 17:30:51 +08:00
std::string TMXOrthoTest::title()
{
return "TMX Orthogonal test";
2010-09-01 17:30:51 +08:00
}
2010-11-18 14:50:28 +08:00
2010-09-01 17:30:51 +08:00
//------------------------------------------------------------------
//
// TMXOrthoTest2
//
//------------------------------------------------------------------
2010-11-18 14:50:28 +08:00
TMXOrthoTest2::TMXOrthoTest2()
{
TMXTiledMap* map = TMXTiledMap::create("TileMaps/orthogonal-test1.tmx");
addChild(map, 0, kTagTileMap);
2010-09-01 17:30:51 +08:00
Size CC_UNUSED s = map->getContentSize();
CCLOG("ContentSize: %f, %f", s.width,s.height);
2010-09-01 17:30:51 +08:00
Array* pChildrenArray = map->getChildren();
SpriteBatchNode* child = NULL;
Object* pObject = NULL;
CCARRAY_FOREACH(pChildrenArray, pObject)
{
child = static_cast<SpriteBatchNode*>(pObject);
2010-09-01 17:30:51 +08:00
if(!child)
break;
2010-09-01 17:30:51 +08:00
child->getTexture()->setAntiAliasTexParameters();
}
2010-09-01 17:30:51 +08:00
map->runAction( ScaleBy::create(2, 0.5f) ) ;
2010-11-18 14:50:28 +08:00
}
2010-09-01 17:30:51 +08:00
std::string TMXOrthoTest2::title()
{
return "TMX Ortho test2";
2010-09-01 17:30:51 +08:00
}
2010-11-18 14:50:28 +08:00
2010-09-01 17:30:51 +08:00
//------------------------------------------------------------------
//
// TMXOrthoTest3
//
//------------------------------------------------------------------
2010-11-18 14:50:28 +08:00
TMXOrthoTest3::TMXOrthoTest3()
{
TMXTiledMap *map = TMXTiledMap::create("TileMaps/orthogonal-test3.tmx");
addChild(map, 0, kTagTileMap);
Size CC_UNUSED s = map->getContentSize();
CCLOG("ContentSize: %f, %f", s.width,s.height);
Array* pChildrenArray = map->getChildren();
SpriteBatchNode* child = NULL;
Object* pObject = NULL;
CCARRAY_FOREACH(pChildrenArray, pObject)
{
child = static_cast<SpriteBatchNode*>(pObject);
if(!child)
break;
child->getTexture()->setAntiAliasTexParameters();
}
map->setScale(0.2f);
2013-07-12 14:11:55 +08:00
map->setAnchorPoint( Point(0.5f, 0.5f) );
2010-11-18 14:50:28 +08:00
}
2010-09-01 17:30:51 +08:00
std::string TMXOrthoTest3::title()
{
return "TMX anchorPoint test";
2010-09-01 17:30:51 +08:00
}
2010-11-18 14:50:28 +08:00
2010-09-01 17:30:51 +08:00
//------------------------------------------------------------------
//
// TMXOrthoTest4
//
//------------------------------------------------------------------
2010-11-18 14:50:28 +08:00
TMXOrthoTest4::TMXOrthoTest4()
{
TMXTiledMap *map = TMXTiledMap::create("TileMaps/orthogonal-test4.tmx");
addChild(map, 0, kTagTileMap);
Size CC_UNUSED s1 = map->getContentSize();
CCLOG("ContentSize: %f, %f", s1.width,s1.height);
Array* pChildrenArray = map->getChildren();
SpriteBatchNode* child = NULL;
Object* pObject = NULL;
CCARRAY_FOREACH(pChildrenArray, pObject)
{
child = static_cast<SpriteBatchNode*>(pObject);
if(!child)
break;
child->getTexture()->setAntiAliasTexParameters();
}
2013-07-12 14:11:55 +08:00
map->setAnchorPoint(Point(0, 0));
TMXLayer* layer = map->layerNamed("Layer 0");
Size s = layer->getLayerSize();
Sprite* sprite;
sprite = layer->getTileAt(Point(0,0));
sprite->setScale(2);
sprite = layer->getTileAt(Point(s.width-1,0));
sprite->setScale(2);
sprite = layer->getTileAt(Point(0,s.height-1));
sprite->setScale(2);
sprite = layer->getTileAt(Point(s.width-1,s.height-1));
sprite->setScale(2);
schedule( schedule_selector(TMXOrthoTest4::removeSprite), 2 );
2010-11-18 14:50:28 +08:00
}
2012-06-08 13:55:28 +08:00
void TMXOrthoTest4::removeSprite(float dt)
2010-11-18 14:50:28 +08:00
{
unschedule(schedule_selector(TMXOrthoTest4::removeSprite));
2010-11-18 14:50:28 +08:00
TMXTiledMap *map = (TMXTiledMap*)getChildByTag(kTagTileMap);
TMXLayer* layer = map->layerNamed("Layer 0");
Size s = layer->getLayerSize();
2010-11-18 14:50:28 +08:00
Sprite* sprite = layer->getTileAt( Point(s.width-1,0) );
layer->removeChild(sprite, true);
2010-09-01 17:30:51 +08:00
}
std::string TMXOrthoTest4::title()
{
return "TMX width/height test";
2010-09-01 17:30:51 +08:00
}
2010-11-18 14:50:28 +08:00
2010-09-01 17:30:51 +08:00
//------------------------------------------------------------------
//
// TMXReadWriteTest
//
//------------------------------------------------------------------
enum
{
SID_UPDATECOL = 100,
SID_REPAINTWITHGID,
SID_REMOVETILES
2010-09-01 17:30:51 +08:00
};
2010-11-18 14:50:28 +08:00
TMXReadWriteTest::TMXReadWriteTest()
{
_gid = 0;
TMXTiledMap* map = TMXTiledMap::create("TileMaps/orthogonal-test2.tmx");
addChild(map, 0, kTagTileMap);
Size CC_UNUSED s = map->getContentSize();
CCLOG("ContentSize: %f, %f", s.width,s.height);
TMXLayer* layer = map->layerNamed("Layer 0");
layer->getTexture()->setAntiAliasTexParameters();
map->setScale( 1 );
Sprite *tile0 = layer->getTileAt(Point(1,63));
Sprite *tile1 = layer->getTileAt(Point(2,63));
Sprite *tile2 = layer->getTileAt(Point(3,62));//Point(1,62));
Sprite *tile3 = layer->getTileAt(Point(2,62));
2013-07-12 14:11:55 +08:00
tile0->setAnchorPoint( Point(0.5f, 0.5f) );
tile1->setAnchorPoint( Point(0.5f, 0.5f) );
tile2->setAnchorPoint( Point(0.5f, 0.5f) );
tile3->setAnchorPoint( Point(0.5f, 0.5f) );
2013-07-12 14:11:55 +08:00
ActionInterval* move = MoveBy::create(0.5f, Point(0,160));
ActionInterval* rotate = RotateBy::create(2, 360);
ActionInterval* scale = ScaleBy::create(2, 5);
ActionInterval* opacity = FadeOut::create(2);
ActionInterval* fadein = FadeIn::create(2);
ActionInterval* scaleback = ScaleTo::create(1, 1);
ActionInstant* finish = CallFuncN::create(CC_CALLBACK_1(TMXReadWriteTest::removeSprite, this));
Sequence* seq0 = Sequence::create(move, rotate, scale, opacity, fadein, scaleback, finish, NULL);
ActionInterval* seq1 = seq0->clone();
ActionInterval* seq2 = seq0->clone();
ActionInterval* seq3 = seq0->clone();
tile0->runAction(seq0);
tile1->runAction(seq1);
tile2->runAction(seq2);
tile3->runAction(seq3);
_gid = layer->getTileGIDAt(Point(0,63));
////----CCLOG("Tile GID at:(0,63) is: %d", _gid);
schedule(schedule_selector(TMXReadWriteTest::updateCol), 2.0f);
2012-11-19 16:28:37 +08:00
schedule(schedule_selector(TMXReadWriteTest::repaintWithGID), 2.05f);
schedule(schedule_selector(TMXReadWriteTest::removeTiles), 1.0f);
////----CCLOG("++++atlas quantity: %d", layer->textureAtlas()->getTotalQuads());
////----CCLOG("++++children: %d", layer->getChildren()->count() );
_gid2 = 0;
2010-11-18 14:50:28 +08:00
}
2010-09-01 17:30:51 +08:00
void TMXReadWriteTest::removeSprite(Node* sender)
2010-09-01 17:30:51 +08:00
{
////----CCLOG("removing tile: %x", sender);
Node* p = ((Node*)sender)->getParent();
2010-09-01 17:30:51 +08:00
if (p)
{
p->removeChild((Node*)sender, true);
}
//////----CCLOG("atlas quantity: %d", p->textureAtlas()->totalQuads());
2010-09-01 17:30:51 +08:00
}
2012-06-08 13:55:28 +08:00
void TMXReadWriteTest::updateCol(float dt)
{
TMXTiledMap* map = (TMXTiledMap*)getChildByTag(kTagTileMap);
TMXLayer *layer = (TMXLayer*)map->getChildByTag(0);
2010-09-01 17:30:51 +08:00
////----CCLOG("++++atlas quantity: %d", layer->textureAtlas()->getTotalQuads());
////----CCLOG("++++children: %d", layer->getChildren()->count() );
2010-09-01 17:30:51 +08:00
Size s = layer->getLayerSize();
2010-09-01 17:30:51 +08:00
for( int y=0; y< s.height; y++ )
{
2013-07-12 14:11:55 +08:00
layer->setTileGID(_gid2, Point((float)3, (float)y));
}
_gid2 = (_gid2 + 1) % 80;
2010-09-01 17:30:51 +08:00
}
2012-06-08 13:55:28 +08:00
void TMXReadWriteTest::repaintWithGID(float dt)
2010-09-01 17:30:51 +08:00
{
// unschedule:_cmd);
TMXTiledMap* map = (TMXTiledMap*)getChildByTag(kTagTileMap);
TMXLayer *layer = (TMXLayer*)map->getChildByTag(0);
Size s = layer->getLayerSize();
for( int x=0; x<s.width;x++)
{
int y = (int)s.height-1;
unsigned int tmpgid = layer->getTileGIDAt( Point((float)x, (float)y) );
2013-07-12 14:11:55 +08:00
layer->setTileGID(tmpgid+1, Point((float)x, (float)y));
}
2010-09-01 17:30:51 +08:00
}
2012-06-08 13:55:28 +08:00
void TMXReadWriteTest::removeTiles(float dt)
2010-09-01 17:30:51 +08:00
{
unschedule(schedule_selector(TMXReadWriteTest::removeTiles));
2010-09-01 17:30:51 +08:00
TMXTiledMap* map = (TMXTiledMap*)getChildByTag(kTagTileMap);
TMXLayer *layer = (TMXLayer*)map->getChildByTag(0);
Size s = layer->getLayerSize();
2010-09-01 17:30:51 +08:00
for( int y=0; y< s.height; y++ )
{
2013-07-12 14:11:55 +08:00
layer->removeTileAt( Point(5.0, (float)y) );
}
2010-09-01 17:30:51 +08:00
}
std::string TMXReadWriteTest::title()
{
return "TMX Read/Write test";
2010-09-01 17:30:51 +08:00
}
2010-11-18 14:50:28 +08:00
2010-09-01 17:30:51 +08:00
//------------------------------------------------------------------
//
// TMXHexTest
//
//------------------------------------------------------------------
2010-11-18 14:50:28 +08:00
TMXHexTest::TMXHexTest()
{
LayerColor* color = LayerColor::create( Color4B(64,64,64,255) );
addChild(color, -1);
TMXTiledMap* map = TMXTiledMap::create("TileMaps/hexa-test.tmx");
addChild(map, 0, kTagTileMap);
Size CC_UNUSED s = map->getContentSize();
CCLOG("ContentSize: %f, %f", s.width,s.height);
2010-11-18 14:50:28 +08:00
}
2010-09-01 17:30:51 +08:00
std::string TMXHexTest::title()
{
return "TMX Hex tes";
2010-09-01 17:30:51 +08:00
}
2010-11-18 14:50:28 +08:00
2010-09-01 17:30:51 +08:00
//------------------------------------------------------------------
//
// TMXIsoTest
//
//------------------------------------------------------------------
2010-11-18 14:50:28 +08:00
TMXIsoTest::TMXIsoTest()
{
LayerColor* color = LayerColor::create( Color4B(64,64,64,255) );
addChild(color, -1);
TMXTiledMap* map = TMXTiledMap::create("TileMaps/iso-test.tmx");
addChild(map, 0, kTagTileMap);
// move map to the center of the screen
Size ms = map->getMapSize();
Size ts = map->getTileSize();
2013-07-12 14:11:55 +08:00
map->runAction( MoveTo::create(1.0f, Point( -ms.width * ts.width/2, -ms.height * ts.height/2 )) );
2010-11-18 14:50:28 +08:00
}
2010-09-01 17:30:51 +08:00
std::string TMXIsoTest::title()
{
return "TMX Isometric test 0";
2010-09-01 17:30:51 +08:00
}
2010-11-18 14:50:28 +08:00
2010-09-01 17:30:51 +08:00
//------------------------------------------------------------------
//
// TMXIsoTest1
//
//------------------------------------------------------------------
2010-11-18 14:50:28 +08:00
TMXIsoTest1::TMXIsoTest1()
{
LayerColor* color = LayerColor::create( Color4B(64,64,64,255) );
addChild(color, -1);
TMXTiledMap *map = TMXTiledMap::create("TileMaps/iso-test1.tmx");
addChild(map, 0, kTagTileMap);
Size CC_UNUSED s = map->getContentSize();
CCLOG("ContentSize: %f, %f", s.width,s.height);
2013-07-12 14:11:55 +08:00
map->setAnchorPoint(Point(0.5f, 0.5f));
2010-11-18 14:50:28 +08:00
}
2010-09-01 17:30:51 +08:00
std::string TMXIsoTest1::title()
{
return "TMX Isometric test + anchorPoint";
2010-09-01 17:30:51 +08:00
}
2010-11-18 14:50:28 +08:00
2010-09-01 17:30:51 +08:00
//------------------------------------------------------------------
//
// TMXIsoTest2
//
//------------------------------------------------------------------
2010-11-18 14:50:28 +08:00
TMXIsoTest2::TMXIsoTest2()
{
LayerColor* color = LayerColor::create( Color4B(64,64,64,255) );
addChild(color, -1);
TMXTiledMap *map = TMXTiledMap::create("TileMaps/iso-test2.tmx");
addChild(map, 0, kTagTileMap);
Size CC_UNUSED s = map->getContentSize();
CCLOG("ContentSize: %f, %f", s.width,s.height);
// move map to the center of the screen
Size ms = map->getMapSize();
Size ts = map->getTileSize();
2013-07-12 14:11:55 +08:00
map->runAction( MoveTo::create(1.0f, Point( -ms.width * ts.width/2, -ms.height * ts.height/2 ) ));
2010-11-18 14:50:28 +08:00
}
2010-09-01 17:30:51 +08:00
std::string TMXIsoTest2::title()
{
return "TMX Isometric test 2";
2010-09-01 17:30:51 +08:00
}
2010-11-18 14:50:28 +08:00
2010-09-01 17:30:51 +08:00
//------------------------------------------------------------------
//
// TMXUncompressedTest
//
//------------------------------------------------------------------
2010-11-18 14:50:28 +08:00
TMXUncompressedTest::TMXUncompressedTest()
{
LayerColor* color = LayerColor::create( Color4B(64,64,64,255) );
addChild(color, -1);
TMXTiledMap *map = TMXTiledMap::create("TileMaps/iso-test2-uncompressed.tmx");
addChild(map, 0, kTagTileMap);
Size CC_UNUSED s = map->getContentSize();
CCLOG("ContentSize: %f, %f", s.width,s.height);
// move map to the center of the screen
Size ms = map->getMapSize();
Size ts = map->getTileSize();
2013-07-12 14:11:55 +08:00
map->runAction(MoveTo::create(1.0f, Point( -ms.width * ts.width/2, -ms.height * ts.height/2 ) ));
// testing release map
Array* pChildrenArray = map->getChildren();
TMXLayer* layer;
Object* pObject = NULL;
CCARRAY_FOREACH(pChildrenArray, pObject)
{
layer= static_cast<TMXLayer*>(pObject);
2010-09-01 17:30:51 +08:00
if(!layer)
break;
2010-09-01 17:30:51 +08:00
layer->releaseMap();
}
2010-09-01 17:30:51 +08:00
2010-11-18 14:50:28 +08:00
}
2010-09-01 17:30:51 +08:00
std::string TMXUncompressedTest::title()
{
return "TMX Uncompressed test";
2010-09-01 17:30:51 +08:00
}
2010-11-18 14:50:28 +08:00
2010-09-01 17:30:51 +08:00
//------------------------------------------------------------------
//
// TMXTilesetTest
//
//------------------------------------------------------------------
2010-11-18 14:50:28 +08:00
TMXTilesetTest::TMXTilesetTest()
{
TMXTiledMap *map = TMXTiledMap::create("TileMaps/orthogonal-test5.tmx");
addChild(map, 0, kTagTileMap);
Size CC_UNUSED s = map->getContentSize();
CCLOG("ContentSize: %f, %f", s.width,s.height);
TMXLayer* layer;
layer = map->layerNamed("Layer 0");
layer->getTexture()->setAntiAliasTexParameters();
layer = map->layerNamed("Layer 1");
layer->getTexture()->setAntiAliasTexParameters();
2010-09-01 17:30:51 +08:00
layer = map->layerNamed("Layer 2");
layer->getTexture()->setAntiAliasTexParameters();
2010-11-18 14:50:28 +08:00
}
2010-09-01 17:30:51 +08:00
std::string TMXTilesetTest::title()
{
return "TMX Tileset test";
2010-09-01 17:30:51 +08:00
}
2010-11-18 14:50:28 +08:00
2010-09-01 17:30:51 +08:00
//------------------------------------------------------------------
//
// TMXOrthoObjectsTest
//
//------------------------------------------------------------------
2010-11-18 14:50:28 +08:00
TMXOrthoObjectsTest::TMXOrthoObjectsTest()
{
TMXTiledMap *map = TMXTiledMap::create("TileMaps/ortho-objects.tmx");
addChild(map, -1, kTagTileMap);
Size CC_UNUSED s = map->getContentSize();
CCLOG("ContentSize: %f, %f", s.width,s.height);
////----CCLOG("----> Iterating over all the group objets");
TMXObjectGroup* group = map->objectGroupNamed("Object Group 1");
Array* objects = group->getObjects();
Dictionary* dict = NULL;
Object* pObj = NULL;
CCARRAY_FOREACH(objects, pObj)
{
dict = static_cast<Dictionary*>(pObj);
if(!dict)
break;
////----CCLOG("object: %x", dict);
}
////----CCLOG("----> Fetching 1 object by name");
// StringToStringDictionary* platform = group->objectNamed("platform");
////----CCLOG("platform: %x", platform);
2010-11-18 14:50:28 +08:00
}
void TMXOrthoObjectsTest::draw()
{
TMXTiledMap* map = (TMXTiledMap*) getChildByTag(kTagTileMap);
TMXObjectGroup* group = map->objectGroupNamed("Object Group 1");
Array* objects = group->getObjects();
Dictionary* dict = NULL;
Object* pObj = NULL;
CCARRAY_FOREACH(objects, pObj)
{
dict = static_cast<Dictionary*>(pObj);
if(!dict)
break;
const char* key = "x";
int x = ((String*)dict->objectForKey(key))->intValue();
key = "y";
int y = ((String*)dict->objectForKey(key))->intValue();//dynamic_cast<NSNumber*>(dict->objectForKey("y"))->getNumber();
key = "width";
int width = ((String*)dict->objectForKey(key))->intValue();//dynamic_cast<NSNumber*>(dict->objectForKey("width"))->getNumber();
key = "height";
int height = ((String*)dict->objectForKey(key))->intValue();//dynamic_cast<NSNumber*>(dict->objectForKey("height"))->getNumber();
glLineWidth(3);
2013-07-12 14:11:55 +08:00
ccDrawLine( Point((float)x, (float)y), Point((float)(x+width), (float)y) );
ccDrawLine( Point((float)(x+width), (float)y), Point((float)(x+width), (float)(y+height)) );
ccDrawLine( Point((float)(x+width), (float)(y+height)), Point((float)x, (float)(y+height)) );
ccDrawLine( Point((float)x, (float)(y+height)), Point((float)x, (float)y) );
glLineWidth(1);
}
2010-11-18 14:50:28 +08:00
}
std::string TMXOrthoObjectsTest::title()
{
return "TMX Ortho object test";
2010-11-18 14:50:28 +08:00
}
std::string TMXOrthoObjectsTest::subtitle()
{
return "You should see a white box around the 3 platforms";
2010-11-18 14:50:28 +08:00
}
2010-09-01 17:30:51 +08:00
//------------------------------------------------------------------
//
// TMXIsoObjectsTest
//
//------------------------------------------------------------------
2010-11-18 14:50:28 +08:00
TMXIsoObjectsTest::TMXIsoObjectsTest()
{
TMXTiledMap* map = TMXTiledMap::create("TileMaps/iso-test-objectgroup.tmx");
addChild(map, -1, kTagTileMap);
Size CC_UNUSED s = map->getContentSize();
CCLOG("ContentSize: %f, %f", s.width,s.height);
2010-11-18 14:50:28 +08:00
TMXObjectGroup* group = map->objectGroupNamed("Object Group 1");
2010-11-18 14:50:28 +08:00
//UxMutableArray* objects = group->objects();
Array* objects = group->getObjects();
//UxMutableDictionary<std::string>* dict;
Dictionary* dict;
Object* pObj = NULL;
CCARRAY_FOREACH(objects, pObj)
{
dict = static_cast<Dictionary*>(pObj);
2010-11-18 14:50:28 +08:00
if(!dict)
break;
2010-11-18 14:50:28 +08:00
////----CCLOG("object: %x", dict);
}
2010-11-18 14:50:28 +08:00
}
void TMXIsoObjectsTest::draw()
{
TMXTiledMap *map = (TMXTiledMap*) getChildByTag(kTagTileMap);
TMXObjectGroup *group = map->objectGroupNamed("Object Group 1");
Array* objects = group->getObjects();
Dictionary* dict;
Object* pObj = NULL;
CCARRAY_FOREACH(objects, pObj)
{
dict = static_cast<Dictionary*>(pObj);
if(!dict)
break;
const char* key = "x";
int x = static_cast<String*>(dict->objectForKey(key))->intValue();
key = "y";
int y = static_cast<String*>(dict->objectForKey(key))->intValue();
key = "width";
int width = static_cast<String*>(dict->objectForKey(key))->intValue();
key = "height";
int height = static_cast<String*>(dict->objectForKey(key))->intValue();
glLineWidth(3);
2013-07-12 14:11:55 +08:00
ccDrawLine( Point(x,y), Point(x+width,y) );
ccDrawLine( Point(x+width,y), Point(x+width,y+height) );
ccDrawLine( Point(x+width,y+height), Point(x,y+height) );
ccDrawLine( Point(x,y+height), Point(x,y) );
glLineWidth(1);
}
2010-11-18 14:50:28 +08:00
}
std::string TMXIsoObjectsTest::title()
{
return "TMX Iso object test";
2010-11-18 14:50:28 +08:00
}
std::string TMXIsoObjectsTest::subtitle()
{
return "You need to parse them manually. See bug #810";
2010-11-18 14:50:28 +08:00
}
2010-09-01 17:30:51 +08:00
//------------------------------------------------------------------
//
// TMXResizeTest
//
//------------------------------------------------------------------
2010-11-18 14:50:28 +08:00
TMXResizeTest::TMXResizeTest()
{
TMXTiledMap* map = TMXTiledMap::create("TileMaps/orthogonal-test5.tmx");
addChild(map, 0, kTagTileMap);
Size CC_UNUSED s = map->getContentSize();
CCLOG("ContentSize: %f, %f", s.width,s.height);
2010-11-18 14:50:28 +08:00
TMXLayer* layer;
layer = map->layerNamed("Layer 0");
2010-11-18 14:50:28 +08:00
Size ls = layer->getLayerSize();
for (unsigned int y = 0; y < ls.height; y++)
{
for (unsigned int x = 0; x < ls.width; x++)
{
2013-07-12 14:11:55 +08:00
layer->setTileGID(1, Point( x, y ) );
}
}
2010-11-18 14:50:28 +08:00
}
std::string TMXResizeTest::title()
{
return "TMX resize test";
2010-11-18 14:50:28 +08:00
}
std::string TMXResizeTest::subtitle()
{
return "Should not crash. Testing issue #740";
2010-11-18 14:50:28 +08:00
}
2010-09-01 17:30:51 +08:00
//------------------------------------------------------------------
//
// TMXIsoZorder
//
//------------------------------------------------------------------
2010-11-18 14:50:28 +08:00
TMXIsoZorder::TMXIsoZorder()
{
TMXTiledMap *map = TMXTiledMap::create("TileMaps/iso-test-zorder.tmx");
addChild(map, 0, kTagTileMap);
2011-02-23 16:47:25 +08:00
Size s = map->getContentSize();
CCLOG("ContentSize: %f, %f", s.width,s.height);
2013-07-12 14:11:55 +08:00
map->setPosition(Point(-s.width/2,0));
_tamara = Sprite::create(s_pPathSister1);
map->addChild(_tamara, map->getChildren()->count() );
_tamara->retain();
int mapWidth = map->getMapSize().width * map->getTileSize().width;
2013-07-12 14:11:55 +08:00
_tamara->setPosition(CC_POINT_PIXELS_TO_POINTS(Point( mapWidth/2,0)));
_tamara->setAnchorPoint(Point(0.5f,0));
2013-07-12 14:11:55 +08:00
ActionInterval* move = MoveBy::create(10, Point(300,250));
ActionInterval* back = move->reverse();
Sequence* seq = Sequence::create(move, back,NULL);
_tamara->runAction( RepeatForever::create(seq) );
schedule( schedule_selector(TMXIsoZorder::repositionSprite) );
2010-11-18 14:50:28 +08:00
}
TMXIsoZorder::~TMXIsoZorder()
{
_tamara->release();
2010-11-18 14:50:28 +08:00
}
void TMXIsoZorder::onExit()
{
unschedule(schedule_selector(TMXIsoZorder::repositionSprite));
TileDemo::onExit();
2010-11-18 14:50:28 +08:00
}
2012-06-08 13:55:28 +08:00
void TMXIsoZorder::repositionSprite(float dt)
2010-11-18 14:50:28 +08:00
{
Point p = _tamara->getPosition();
p = CC_POINT_POINTS_TO_PIXELS(p);
Node *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(_tamara, newZ);
2010-11-18 14:50:28 +08:00
}
std::string TMXIsoZorder::title()
{
return "TMX Iso Zorder";
2010-11-18 14:50:28 +08:00
}
std::string TMXIsoZorder::subtitle()
{
return "Sprite should hide behind the trees";
2010-11-18 14:50:28 +08:00
}
2010-09-01 17:30:51 +08:00
//------------------------------------------------------------------
//
// TMXOrthoZorder
//
//------------------------------------------------------------------
2010-11-18 14:50:28 +08:00
TMXOrthoZorder::TMXOrthoZorder()
{
TMXTiledMap *map = TMXTiledMap::create("TileMaps/orthogonal-test-zorder.tmx");
addChild(map, 0, kTagTileMap);
Size CC_UNUSED s = map->getContentSize();
CCLOG("ContentSize: %f, %f", s.width,s.height);
_tamara = Sprite::create(s_pPathSister1);
map->addChild(_tamara, map->getChildren()->count());
_tamara->retain();
2013-07-12 14:11:55 +08:00
_tamara->setAnchorPoint(Point(0.5f,0));
2013-07-12 14:11:55 +08:00
ActionInterval* move = MoveBy::create(10, Point(400,450));
ActionInterval* back = move->reverse();
Sequence* seq = Sequence::create(move, back,NULL);
_tamara->runAction( RepeatForever::create(seq));
schedule( schedule_selector(TMXOrthoZorder::repositionSprite));
2010-11-18 14:50:28 +08:00
}
TMXOrthoZorder::~TMXOrthoZorder()
{
_tamara->release();
2010-11-18 14:50:28 +08:00
}
2012-06-08 13:55:28 +08:00
void TMXOrthoZorder::repositionSprite(float dt)
2010-11-18 14:50:28 +08:00
{
Point p = _tamara->getPosition();
p = CC_POINT_POINTS_TO_PIXELS(p);
Node* 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
2010-11-18 14:50:28 +08:00
// -10: customization for this particular sample
int newZ = 4 - ( (p.y-10) / 81);
newZ = max(newZ,0);
2010-11-18 14:50:28 +08:00
map->reorderChild(_tamara, newZ);
2010-11-18 14:50:28 +08:00
}
std::string TMXOrthoZorder::title()
{
return "TMX Ortho Zorder";
2010-11-18 14:50:28 +08:00
}
std::string TMXOrthoZorder::subtitle()
{
return "Sprite should hide behind the trees";
2010-11-18 14:50:28 +08:00
}
2010-09-01 17:30:51 +08:00
//------------------------------------------------------------------
//
// TMXIsoVertexZ
//
//------------------------------------------------------------------
2010-11-18 14:50:28 +08:00
TMXIsoVertexZ::TMXIsoVertexZ()
{
TMXTiledMap *map = TMXTiledMap::create("TileMaps/iso-test-vertexz.tmx");
addChild(map, 0, kTagTileMap);
Size s = map->getContentSize();
2013-07-12 14:11:55 +08:00
map->setPosition( Point(-s.width/2,0) );
CCLOG("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 Sprite and it will work OK.
TMXLayer* layer = map->layerNamed("Trees");
_tamara = layer->getTileAt( Point(29,29) );
_tamara->retain();
2013-07-12 14:11:55 +08:00
ActionInterval* move = MoveBy::create(10, Point(300,250) * (1/CC_CONTENT_SCALE_FACTOR()));
ActionInterval* back = move->reverse();
Sequence* seq = Sequence::create(move, back,NULL);
_tamara->runAction( RepeatForever::create(seq) );
schedule( schedule_selector(TMXIsoVertexZ::repositionSprite));
2010-11-18 14:50:28 +08:00
}
TMXIsoVertexZ::~TMXIsoVertexZ()
{
_tamara->release();
2010-11-18 14:50:28 +08:00
}
2012-06-08 13:55:28 +08:00
void TMXIsoVertexZ::repositionSprite(float dt)
2010-11-18 14:50:28 +08:00
{
// tile height is 64x32
// map size: 30x30
Point p = _tamara->getPosition();
p = CC_POINT_POINTS_TO_PIXELS(p);
float newZ = -(p.y+32) /16;
_tamara->setVertexZ( newZ );
2010-11-18 14:50:28 +08:00
}
void TMXIsoVertexZ::onEnter()
{
TileDemo::onEnter();
// TIP: 2d projection should be used
Director::getInstance()->setProjection(kDirectorProjection2D);
2010-11-18 14:50:28 +08:00
}
void TMXIsoVertexZ::onExit()
{
// At exit use any other projection.
// Director::getInstance()->setProjection:kDirectorProjection3D);
TileDemo::onExit();
2010-11-18 14:50:28 +08:00
}
std::string TMXIsoVertexZ::title()
{
return "TMX Iso VertexZ";
2010-11-18 14:50:28 +08:00
}
std::string TMXIsoVertexZ::subtitle()
{
return "Sprite should hide behind the trees";
2010-11-18 14:50:28 +08:00
}
2010-09-01 17:30:51 +08:00
//------------------------------------------------------------------
//
// TMXOrthoVertexZ
//
//------------------------------------------------------------------
2010-11-18 14:50:28 +08:00
TMXOrthoVertexZ::TMXOrthoVertexZ()
{
TMXTiledMap *map = TMXTiledMap::create("TileMaps/orthogonal-test-vertexz.tmx");
addChild(map, 0, kTagTileMap);
Size CC_UNUSED s = map->getContentSize();
CCLOG("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 Sprite and it will work OK.
TMXLayer* layer = map->layerNamed("trees");
_tamara = layer->getTileAt(Point(0,11));
CCLOG("%p vertexZ: %f", _tamara, _tamara->getVertexZ());
_tamara->retain();
2010-11-18 14:50:28 +08:00
2013-07-12 14:11:55 +08:00
ActionInterval* move = MoveBy::create(10, Point(400,450) * (1/CC_CONTENT_SCALE_FACTOR()));
ActionInterval* back = move->reverse();
Sequence* seq = Sequence::create(move, back,NULL);
_tamara->runAction( RepeatForever::create(seq));
schedule(schedule_selector(TMXOrthoVertexZ::repositionSprite));
2010-11-18 14:50:28 +08:00
}
TMXOrthoVertexZ::~TMXOrthoVertexZ()
{
_tamara->release();
2010-11-18 14:50:28 +08:00
}
2012-06-08 13:55:28 +08:00
void TMXOrthoVertexZ::repositionSprite(float dt)
2010-11-18 14:50:28 +08:00
{
// tile height is 101x81
// map size: 12x12
Point p = _tamara->getPosition();
p = CC_POINT_POINTS_TO_PIXELS(p);
_tamara->setVertexZ( -( (p.y+81) /81) );
2010-11-18 14:50:28 +08:00
}
void TMXOrthoVertexZ::onEnter()
{
TileDemo::onEnter();
// TIP: 2d projection should be used
Director::getInstance()->setProjection(kDirectorProjection2D);
2010-11-18 14:50:28 +08:00
}
void TMXOrthoVertexZ::onExit()
{
// At exit use any other projection.
// Director::getInstance()->setProjection:kDirectorProjection3D);
TileDemo::onExit();
2010-11-18 14:50:28 +08:00
}
std::string TMXOrthoVertexZ::title()
{
return "TMX Ortho vertexZ";
2010-11-18 14:50:28 +08:00
}
std::string TMXOrthoVertexZ::subtitle()
{
return "Sprite should hide behind the trees";
2010-11-18 14:50:28 +08:00
}
2010-09-01 17:30:51 +08:00
//------------------------------------------------------------------
//
// TMXIsoMoveLayer
//
//------------------------------------------------------------------
2010-11-18 14:50:28 +08:00
TMXIsoMoveLayer::TMXIsoMoveLayer()
{
TMXTiledMap* map = TMXTiledMap::create("TileMaps/iso-test-movelayer.tmx");
addChild(map, 0, kTagTileMap);
2013-07-12 14:11:55 +08:00
map->setPosition(Point(-700,-50));
2010-11-18 14:50:28 +08:00
Size CC_UNUSED s = map->getContentSize();
CCLOG("ContentSize: %f, %f", s.width,s.height);
2010-11-18 14:50:28 +08:00
}
std::string TMXIsoMoveLayer::title()
{
return "TMX Iso Move Layer";
2010-11-18 14:50:28 +08:00
}
std::string TMXIsoMoveLayer::subtitle()
{
return "Trees should be horizontally aligned";
2010-11-18 14:50:28 +08:00
}
2010-09-01 17:30:51 +08:00
//------------------------------------------------------------------
//
// TMXOrthoMoveLayer
//
//------------------------------------------------------------------
2010-11-18 14:50:28 +08:00
TMXOrthoMoveLayer::TMXOrthoMoveLayer()
{
TMXTiledMap *map = TMXTiledMap::create("TileMaps/orthogonal-test-movelayer.tmx");
addChild(map, 0, kTagTileMap);
2010-11-18 14:50:28 +08:00
Size CC_UNUSED s = map->getContentSize();
CCLOG("ContentSize: %f, %f", s.width,s.height);
2010-11-18 14:50:28 +08:00
}
std::string TMXOrthoMoveLayer::title()
{
return "TMX Ortho Move Layer";
2010-11-18 14:50:28 +08:00
}
std::string TMXOrthoMoveLayer::subtitle()
{
return "Trees should be horizontally aligned";
2010-11-18 14:50:28 +08:00
}
//------------------------------------------------------------------
//
// TMXTilePropertyTest
//
//------------------------------------------------------------------
TMXTilePropertyTest::TMXTilePropertyTest()
{
TMXTiledMap *map = TMXTiledMap::create("TileMaps/ortho-tile-property.tmx");
addChild(map ,0 ,kTagTileMap);
for(int i=1;i<=20;i++){
CCLog("GID:%i, Properties:%p", i, map->propertiesForGID(i));
}
}
std::string TMXTilePropertyTest::title()
{
return "TMX Tile Property Test";
}
std::string TMXTilePropertyTest::subtitle()
{
return "In the console you should see tile properties";
}
//------------------------------------------------------------------
//
// TMXOrthoFlipTest
//
//------------------------------------------------------------------
TMXOrthoFlipTest::TMXOrthoFlipTest()
{
TMXTiledMap *map = TMXTiledMap::create("TileMaps/ortho-rotation-test.tmx");
addChild(map, 0, kTagTileMap);
Size CC_UNUSED s = map->getContentSize();
CCLog("ContentSize: %f, %f", s.width,s.height);
Object* pObj = NULL;
CCARRAY_FOREACH(map->getChildren(), pObj)
{
SpriteBatchNode* child = static_cast<SpriteBatchNode*>(pObj);
child->getTexture()->setAntiAliasTexParameters();
}
ScaleBy* action = ScaleBy::create(2, 0.5f);
map->runAction(action);
}
std::string TMXOrthoFlipTest::title()
{
return "TMX tile flip test";
}
//------------------------------------------------------------------
//
// TMXOrthoFlipRunTimeTest
//
//------------------------------------------------------------------
TMXOrthoFlipRunTimeTest::TMXOrthoFlipRunTimeTest()
{
TMXTiledMap *map = TMXTiledMap::create("TileMaps/ortho-rotation-test.tmx");
addChild(map, 0, kTagTileMap);
Size s = map->getContentSize();
CCLog("ContentSize: %f, %f", s.width,s.height);
Object* pObj = NULL;
CCARRAY_FOREACH(map->getChildren(), pObj)
{
SpriteBatchNode* child = static_cast<SpriteBatchNode*>(pObj);
child->getTexture()->setAntiAliasTexParameters();
}
ScaleBy* action = ScaleBy::create(2, 0.5f);
map->runAction(action);
schedule(schedule_selector(TMXOrthoFlipRunTimeTest::flipIt), 1.0f);
}
std::string TMXOrthoFlipRunTimeTest::title()
{
return "TMX tile flip run time test";
}
std::string TMXOrthoFlipRunTimeTest::subtitle()
{
return "in 2 sec bottom left tiles will flip";
}
2012-06-08 13:55:28 +08:00
void TMXOrthoFlipRunTimeTest::flipIt(float dt)
{
TMXTiledMap *map = (TMXTiledMap*) getChildByTag(kTagTileMap);
TMXLayer *layer = map->layerNamed("Layer 0");
//blue diamond
2013-07-12 14:11:55 +08:00
Point tileCoord = Point(1,10);
int flags;
unsigned int GID = layer->getTileGIDAt(tileCoord, (ccTMXTileFlags*)&flags);
// Vertical
if( flags & kTMXTileVerticalFlag )
flags &= ~kTMXTileVerticalFlag;
else
flags |= kTMXTileVerticalFlag;
layer->setTileGID(GID ,tileCoord, (ccTMXTileFlags)flags);
2013-07-12 14:11:55 +08:00
tileCoord = Point(1,8);
GID = layer->getTileGIDAt(tileCoord, (ccTMXTileFlags*)&flags);
// Vertical
if( flags & kTMXTileVerticalFlag )
flags &= ~kTMXTileVerticalFlag;
else
flags |= kTMXTileVerticalFlag;
layer->setTileGID(GID ,tileCoord, (ccTMXTileFlags)flags);
2013-07-12 14:11:55 +08:00
tileCoord = Point(2,8);
GID = layer->getTileGIDAt(tileCoord, (ccTMXTileFlags*)&flags);
// Horizontal
if( flags & kTMXTileHorizontalFlag )
flags &= ~kTMXTileHorizontalFlag;
else
flags |= kTMXTileHorizontalFlag;
layer->setTileGID(GID, tileCoord, (ccTMXTileFlags)flags);
}
//------------------------------------------------------------------
//
// TMXOrthoFromXMLTest
//
//------------------------------------------------------------------
TMXOrthoFromXMLTest::TMXOrthoFromXMLTest()
{
string resources = "TileMaps"; // partial paths are OK as resource paths.
string file = resources + "/orthogonal-test1.tmx";
String* str = String::createWithContentsOfFile(FileUtils::getInstance()->fullPathForFilename(file.c_str()).c_str());
CCASSERT(str != NULL, "Unable to open file");
TMXTiledMap *map = TMXTiledMap::createWithXML(str->getCString() ,resources.c_str());
addChild(map, 0, kTagTileMap);
Size s = map->getContentSize();
CCLog("ContentSize: %f, %f", s.width,s.height);
Object* pObj = NULL;
CCARRAY_FOREACH(map->getChildren(), pObj)
{
SpriteBatchNode* child = static_cast<SpriteBatchNode*>(pObj);
child->getTexture()->setAntiAliasTexParameters();
}
ScaleBy* action = ScaleBy::create(2, 0.5f);
map->runAction(action);
}
std::string TMXOrthoFromXMLTest::title()
{
return "TMX created from XML test";
}
2011-02-23 16:47:25 +08:00
//------------------------------------------------------------------
//
// TMXBug987
//
//------------------------------------------------------------------
TMXBug987::TMXBug987()
{
TMXTiledMap *map = TMXTiledMap::create("TileMaps/orthogonal-test6.tmx");
addChild(map, 0, kTagTileMap);
Size CC_UNUSED s1 = map->getContentSize();
CCLOG("ContentSize: %f, %f", s1.width,s1.height);
Array* childs = map->getChildren();
TMXLayer* node;
Object* pObject = NULL;
CCARRAY_FOREACH(childs, pObject)
{
node = static_cast<TMXLayer*>(pObject);
CC_BREAK_IF(!node);
node->getTexture()->setAntiAliasTexParameters();
}
2013-07-12 14:11:55 +08:00
map->setAnchorPoint(Point(0, 0));
TMXLayer *layer = map->layerNamed("Tile Layer 1");
2013-07-12 14:11:55 +08:00
layer->setTileGID(3, Point(2,2));
}
std::string TMXBug987::title()
{
return "TMX Bug 987";
}
std::string TMXBug987::subtitle()
{
return "You should see an square";
}
2011-02-23 16:47:25 +08:00
//------------------------------------------------------------------
//
// TMXBug787
//
//------------------------------------------------------------------
TMXBug787::TMXBug787()
{
TMXTiledMap *map = TMXTiledMap::create("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";
}
2010-09-01 17:30:51 +08:00
//------------------------------------------------------------------
//
// TileDemo
//
//------------------------------------------------------------------
2010-11-18 14:50:28 +08:00
2010-09-01 17:30:51 +08:00
enum
{
IDC_NEXT = 100,
IDC_BACK,
IDC_RESTART
2010-09-01 17:30:51 +08:00
};
2010-11-18 14:50:28 +08:00
static int sceneIdx = -1;
#define MAX_LAYER 28
2010-09-01 17:30:51 +08:00
Layer* createTileMalayer(int nIndex)
2010-09-01 17:30:51 +08:00
{
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 TMXOrthoFlipTest();
case 21: return new TMXOrthoFlipRunTimeTest();
case 22: return new TMXOrthoFromXMLTest();
case 23: return new TileMapTest();
case 24: return new TileMapEditTest();
case 25: return new TMXBug987();
case 26: return new TMXBug787();
case 27: return new TMXGIDObjectsTest();
}
2010-09-01 17:30:51 +08:00
return NULL;
2010-09-01 17:30:51 +08:00
}
Layer* nextTileMapAction()
2010-09-01 17:30:51 +08:00
{
sceneIdx++;
sceneIdx = sceneIdx % MAX_LAYER;
2010-09-01 17:30:51 +08:00
Layer* layer = createTileMalayer(sceneIdx);
layer->autorelease();
2010-09-01 17:30:51 +08:00
return layer;
2010-09-01 17:30:51 +08:00
}
Layer* backTileMapAction()
2010-09-01 17:30:51 +08:00
{
sceneIdx--;
int total = MAX_LAYER;
if( sceneIdx < 0 )
sceneIdx += total;
Layer* layer = createTileMalayer(sceneIdx);
layer->autorelease();
2010-09-01 17:30:51 +08:00
return layer;
2010-09-01 17:30:51 +08:00
}
Layer* restartTileMapAction()
2010-09-01 17:30:51 +08:00
{
Layer* layer = createTileMalayer(sceneIdx);
layer->autorelease();
2010-09-01 17:30:51 +08:00
return layer;
2010-11-18 14:50:28 +08:00
}
TileDemo::TileDemo(void)
: BaseTest()
2010-11-18 14:50:28 +08:00
{
setTouchEnabled( true );
2010-11-18 14:50:28 +08:00
}
TileDemo::~TileDemo(void)
{
}
2010-09-01 17:30:51 +08:00
std::string TileDemo::title()
{
return "No title";
2010-09-01 17:30:51 +08:00
}
std::string TileDemo::subtitle()
{
return "drag the screen";
2010-09-01 17:30:51 +08:00
}
void TileDemo::onEnter()
{
BaseTest::onEnter();
2010-09-01 17:30:51 +08:00
}
void TileDemo::restartCallback(Object* pSender)
2010-09-01 17:30:51 +08:00
{
Scene* s = new TileMapTestScene();
s->addChild(restartTileMapAction());
2010-09-01 17:30:51 +08:00
Director::getInstance()->replaceScene(s);
s->release();
2010-09-01 17:30:51 +08:00
}
void TileDemo::nextCallback(Object* pSender)
2010-09-01 17:30:51 +08:00
{
Scene* s = new TileMapTestScene();
s->addChild( nextTileMapAction() );
Director::getInstance()->replaceScene(s);
s->release();
2010-09-01 17:30:51 +08:00
}
void TileDemo::backCallback(Object* pSender)
2010-09-01 17:30:51 +08:00
{
Scene* s = new TileMapTestScene();
s->addChild( backTileMapAction() );
Director::getInstance()->replaceScene(s);
s->release();
2010-09-01 17:30:51 +08:00
}
2010-11-18 14:50:28 +08:00
void TileDemo::ccTouchesMoved(Set *pTouches, Event *pEvent)
2010-09-01 17:30:51 +08:00
{
Touch *touch = (Touch*)pTouches->anyObject();
2012-11-19 16:28:37 +08:00
Point diff = touch->getDelta();
Node *node = getChildByTag(kTagTileMap);
Point currentPos = node->getPosition();
node->setPosition(currentPos + diff);
2010-11-18 14:50:28 +08:00
}
void TileMapTestScene::runThisTest()
{
Layer* layer = nextTileMapAction();
addChild(layer);
2010-11-18 14:50:28 +08:00
// fix bug #486, #419.
// "test" is the default value in Director::setGLDefaultValues()
// but TransitionTest may setDepthTest(false), we should revert it here
Director::getInstance()->setDepthTest(true);
Director::getInstance()->replaceScene(this);
2010-11-18 14:50:28 +08:00
}
2011-07-06 14:56:05 +08:00
TMXGIDObjectsTest::TMXGIDObjectsTest()
2011-07-06 14:56:05 +08:00
{
TMXTiledMap *map = TMXTiledMap::create("TileMaps/test-object-layer.tmx");
addChild(map, -1, kTagTileMap);
2011-07-06 14:56:05 +08:00
Size CC_UNUSED s = map->getContentSize();
CCLOG("Contentsize: %f, %f", s.width, s.height);
2011-07-06 14:56:05 +08:00
CCLOG("----> Iterating over all the group objets");
//CCTMXObjectGroup *group = map->objectGroupNamed("Object Layer 1");
2011-07-06 14:56:05 +08:00
}
void TMXGIDObjectsTest::draw()
2011-07-06 14:56:05 +08:00
{
TMXTiledMap *map = (TMXTiledMap*)getChildByTag(kTagTileMap);
TMXObjectGroup *group = map->objectGroupNamed("Object Layer 1");
2011-07-06 14:56:05 +08:00
Array *array = group->getObjects();
Dictionary* dict;
Object* pObj = NULL;
CCARRAY_FOREACH(array, pObj)
{
dict = static_cast<Dictionary*>(pObj);
if(!dict)
{
break;
}
const char* key = "x";
int x = ((String*)dict->objectForKey(key))->intValue();
key = "y";
int y = ((String*)dict->objectForKey(key))->intValue();
key = "width";
int width = ((String*)dict->objectForKey(key))->intValue();
key = "height";
int height = ((String*)dict->objectForKey(key))->intValue();
glLineWidth(3);
2013-07-12 14:11:55 +08:00
ccDrawLine(Point(x, y), Point(x + width, y));
ccDrawLine(Point(x + width, y), Point(x + width, y + height));
ccDrawLine(Point(x + width,y + height), Point(x,y + height));
ccDrawLine(Point(x,y + height), Point(x,y));
glLineWidth(1);
}
2011-07-06 14:56:05 +08:00
}
string TMXGIDObjectsTest::title()
2011-07-06 14:56:05 +08:00
{
return "TMX GID objects";
2011-07-06 14:56:05 +08:00
}
string TMXGIDObjectsTest::subtitle()
2011-07-06 14:56:05 +08:00
{
return "Tiles are created from an object group";
2011-07-06 14:56:05 +08:00
}