2010-11-18 14:50:28 +08:00
|
|
|
#include "TileMapTest.h"
|
|
|
|
#include "../testResource.h"
|
|
|
|
|
2010-09-01 17:30:51 +08:00
|
|
|
enum
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
kTagTileMap = 1,
|
2010-11-18 14:50:28 +08:00
|
|
|
};
|
|
|
|
|
2011-07-08 15:57:46 +08:00
|
|
|
CCLayer* nextTileMapAction();
|
|
|
|
CCLayer* backTileMapAction();
|
|
|
|
CCLayer* restartTileMapAction();
|
|
|
|
|
2010-09-01 17:30:51 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TileMapTest
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2010-11-18 14:50:28 +08:00
|
|
|
TileMapTest::TileMapTest()
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCTileMapAtlas* map = CCTileMapAtlas::create(s_TilesPng, s_LevelMapTga, 16, 16);
|
2012-04-19 14:35:52 +08:00
|
|
|
// Convert it to "alias" (GL_LINEAR filtering)
|
|
|
|
map->getTexture()->setAntiAliasTexParameters();
|
|
|
|
|
|
|
|
CCSize s = map->getContentSize();
|
2012-06-11 14:44:32 +08:00
|
|
|
CCLOG("ContentSize: %f, %f", s.width,s.height);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// 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) );
|
2011-02-23 16:47:25 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCScaleBy *scale = CCScaleBy::create(4, 0.8f);
|
2011-05-12 10:52:10 +08:00
|
|
|
CCActionInterval *scaleBack = scale->reverse();
|
|
|
|
|
2012-12-10 14:12:56 +08:00
|
|
|
CCSequence* seq = CCSequence::create(scale, scaleBack, NULL);
|
2011-05-12 10:52:10 +08:00
|
|
|
|
2012-12-10 14:12:56 +08:00
|
|
|
map->runAction(CCRepeatForever::create(seq));
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
2010-09-01 17:30:51 +08:00
|
|
|
|
|
|
|
std::string TileMapTest::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
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()
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCTileMapAtlas* map = CCTileMapAtlas::create(s_TilesPng, s_LevelMapTga, 16, 16);
|
2012-04-19 14:35:52 +08:00
|
|
|
// Create an Aliased Atlas
|
|
|
|
map->getTexture()->setAliasTexParameters();
|
|
|
|
|
|
|
|
CCSize s = map->getContentSize();
|
2012-06-11 14:44:32 +08:00
|
|
|
CCLOG("ContentSize: %f, %f", s.width,s.height);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// 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:
|
2012-06-11 14:44:32 +08:00
|
|
|
schedule(schedule_selector(TileMapEditTest::updateMap), 0.2f);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
|
|
|
map->setAnchorPoint( ccp(0, 0) );
|
|
|
|
map->setPosition( ccp(-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
|
|
|
{
|
2012-04-19 14:35:52 +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
|
|
|
|
|
|
|
|
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) );
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TileMapEditTest::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
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()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
//
|
|
|
|
// Test orthogonal with 3d camera and anti-alias textures
|
|
|
|
//
|
|
|
|
// it should not flicker. No artifacts should appear
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
//CCLayerColor* color = CCLayerColor::create( ccc4(64,64,64,255) );
|
2012-04-19 14:35:52 +08:00
|
|
|
//addChild(color, -1);
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCTMXTiledMap* map = CCTMXTiledMap::create("TileMaps/orthogonal-test2.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
|
|
|
CCSize s = map->getContentSize();
|
2012-06-11 14:44:32 +08:00
|
|
|
CCLOG("ContentSize: %f, %f", s.width,s.height);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
CCArray * pChildrenArray = map->getChildren();
|
|
|
|
CCSpriteBatchNode* child = NULL;
|
2011-04-21 14:46:15 +08:00
|
|
|
CCObject* pObject = NULL;
|
2012-04-19 14:35:52 +08:00
|
|
|
CCARRAY_FOREACH(pChildrenArray, pObject)
|
|
|
|
{
|
|
|
|
child = (CCSpriteBatchNode*)pObject;
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
if(!child)
|
|
|
|
break;
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
child->getTexture()->setAntiAliasTexParameters();
|
|
|
|
}
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +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()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
TileDemo::onEnter();
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCDirector::sharedDirector()->setProjection(kCCDirectorProjection3D);
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMXOrthoTest::onExit()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCDirector::sharedDirector()->setProjection(kCCDirectorProjection2D);
|
|
|
|
TileDemo::onExit();
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
2010-09-01 17:30:51 +08:00
|
|
|
|
|
|
|
std::string TMXOrthoTest::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
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()
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCTMXTiledMap* map = CCTMXTiledMap::create("TileMaps/orthogonal-test1.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCSize s = map->getContentSize();
|
|
|
|
////----UXLOG("ContentSize: %f, %f", s.width,s.height);
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCArray* pChildrenArray = map->getChildren();
|
|
|
|
CCSpriteBatchNode* child = NULL;
|
2011-04-21 14:46:15 +08:00
|
|
|
CCObject* pObject = NULL;
|
2012-04-19 14:35:52 +08:00
|
|
|
CCARRAY_FOREACH(pChildrenArray, pObject)
|
|
|
|
{
|
|
|
|
child = (CCSpriteBatchNode*)pObject;
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
if(!child)
|
|
|
|
break;
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
child->getTexture()->setAntiAliasTexParameters();
|
|
|
|
}
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
map->runAction( CCScaleBy::create(2, 0.5f) ) ;
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
2010-09-01 17:30:51 +08:00
|
|
|
|
|
|
|
std::string TMXOrthoTest2::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
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()
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCTMXTiledMap *map = CCTMXTiledMap::create("TileMaps/orthogonal-test3.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
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) );
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
2010-09-01 17:30:51 +08:00
|
|
|
|
|
|
|
std::string TMXOrthoTest3::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
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()
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCTMXTiledMap *map = CCTMXTiledMap::create("TileMaps/orthogonal-test4.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
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 );
|
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
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
unschedule(schedule_selector(TMXOrthoTest4::removeSprite));
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCTMXTiledMap *map = (CCTMXTiledMap*)getChildByTag(kTagTileMap);
|
|
|
|
CCTMXLayer* layer = map->layerNamed("Layer 0");
|
|
|
|
CCSize s = layer->getLayerSize();
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCSprite* sprite = layer->tileAt( ccp(s.width-1,0) );
|
|
|
|
layer->removeChild(sprite, true);
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoTest4::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
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
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
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()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
m_gid = 0;
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCTMXTiledMap* map = CCTMXTiledMap::create("TileMaps/orthogonal-test2.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
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) );
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCActionInterval* move = CCMoveBy::create(0.5f, ccp(0,160));
|
|
|
|
CCActionInterval* rotate = CCRotateBy::create(2, 360);
|
|
|
|
CCActionInterval* scale = CCScaleBy::create(2, 5);
|
|
|
|
CCActionInterval* opacity = CCFadeOut::create(2);
|
|
|
|
CCActionInterval* fadein = CCFadeIn::create(2);
|
|
|
|
CCActionInterval* scaleback = CCScaleTo::create(1, 1);
|
|
|
|
CCActionInstant* finish = CCCallFuncN::create(this, callfuncN_selector(TMXReadWriteTest::removeSprite));
|
2012-12-10 14:12:56 +08:00
|
|
|
CCSequence* seq0 = CCSequence::create(move, rotate, scale, opacity, fadein, scaleback, finish, NULL);
|
2012-04-19 14:35:52 +08:00
|
|
|
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);
|
2012-11-19 16:28:37 +08:00
|
|
|
schedule(schedule_selector(TMXReadWriteTest::repaintWithGID), 2.05f);
|
2012-04-19 14:35:52 +08:00
|
|
|
schedule(schedule_selector(TMXReadWriteTest::removeTiles), 1.0f);
|
|
|
|
|
|
|
|
////----UXLOG("++++atlas quantity: %d", layer->textureAtlas()->getTotalQuads());
|
|
|
|
////----UXLOG("++++children: %d", layer->getChildren()->count() );
|
|
|
|
|
|
|
|
m_gid2 = 0;
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2010-09-03 11:10:32 +08:00
|
|
|
void TMXReadWriteTest::removeSprite(CCNode* sender)
|
2010-09-01 17:30:51 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
////----UXLOG("removing tile: %x", sender);
|
|
|
|
CCNode* p = ((CCNode*)sender)->getParent();
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
if (p)
|
|
|
|
{
|
2010-09-06 09:33:46 +08:00
|
|
|
p->removeChild((CCNode*)sender, true);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//////----UXLOG("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)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
CCTMXTiledMap* map = (CCTMXTiledMap*)getChildByTag(kTagTileMap);
|
|
|
|
CCTMXLayer *layer = (CCTMXLayer*)map->getChildByTag(0);
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
////----UXLOG("++++atlas quantity: %d", layer->textureAtlas()->getTotalQuads());
|
|
|
|
////----UXLOG("++++children: %d", layer->getChildren()->count() );
|
2010-09-01 17:30:51 +08:00
|
|
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCSize s = layer->getLayerSize();
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
for( int y=0; y< s.height; y++ )
|
|
|
|
{
|
|
|
|
layer->setTileGID(m_gid2, ccp((float)3, (float)y));
|
|
|
|
}
|
|
|
|
|
|
|
|
m_gid2 = (m_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
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// 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));
|
|
|
|
}
|
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
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
unschedule(schedule_selector(TMXReadWriteTest::removeTiles));
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCTMXTiledMap* map = (CCTMXTiledMap*)getChildByTag(kTagTileMap);
|
|
|
|
CCTMXLayer *layer = (CCTMXLayer*)map->getChildByTag(0);
|
|
|
|
CCSize s = layer->getLayerSize();
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
for( int y=0; y< s.height; y++ )
|
|
|
|
{
|
|
|
|
layer->removeTileAt( ccp(5.0, (float)y) );
|
|
|
|
}
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string TMXReadWriteTest::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
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()
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCLayerColor* color = CCLayerColor::create( ccc4(64,64,64,255) );
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(color, -1);
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCTMXTiledMap* map = CCTMXTiledMap::create("TileMaps/hexa-test.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
|
|
|
CCSize s = map->getContentSize();
|
|
|
|
////----UXLOG("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()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
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()
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCLayerColor* color = CCLayerColor::create( ccc4(64,64,64,255) );
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(color, -1);
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCTMXTiledMap* map = CCTMXTiledMap::create("TileMaps/iso-test.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
|
|
|
// move map to the center of the screen
|
|
|
|
CCSize ms = map->getMapSize();
|
|
|
|
CCSize ts = map->getTileSize();
|
2012-06-14 15:13:16 +08:00
|
|
|
map->runAction( CCMoveTo::create(1.0f, ccp( -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()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
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()
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCLayerColor* color = CCLayerColor::create( ccc4(64,64,64,255) );
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(color, -1);
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCTMXTiledMap *map = CCTMXTiledMap::create("TileMaps/iso-test1.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
|
|
|
CCSize s = map->getContentSize();
|
|
|
|
////----UXLOG("ContentSize: %f, %f", s.width,s.height);
|
|
|
|
|
|
|
|
map->setAnchorPoint(ccp(0.5f, 0.5f));
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
2010-09-01 17:30:51 +08:00
|
|
|
|
|
|
|
std::string TMXIsoTest1::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
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()
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCLayerColor* color = CCLayerColor::create( ccc4(64,64,64,255) );
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(color, -1);
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCTMXTiledMap *map = CCTMXTiledMap::create("TileMaps/iso-test2.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
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();
|
2012-06-14 15:13:16 +08:00
|
|
|
map->runAction( CCMoveTo::create(1.0f, ccp( -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()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
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()
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCLayerColor* color = CCLayerColor::create( ccc4(64,64,64,255) );
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(color, -1);
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCTMXTiledMap *map = CCTMXTiledMap::create("TileMaps/iso-test2-uncompressed.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
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();
|
2012-06-14 15:13:16 +08:00
|
|
|
map->runAction(CCMoveTo::create(1.0f, ccp( -ms.width * ts.width/2, -ms.height * ts.height/2 ) ));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// testing release map
|
|
|
|
CCArray* pChildrenArray = map->getChildren();
|
|
|
|
CCTMXLayer* layer;
|
2011-04-21 14:46:15 +08:00
|
|
|
CCObject* pObject = NULL;
|
2012-04-19 14:35:52 +08:00
|
|
|
CCARRAY_FOREACH(pChildrenArray, pObject)
|
|
|
|
{
|
|
|
|
layer= (CCTMXLayer*)pObject;
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
if(!layer)
|
|
|
|
break;
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +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()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
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()
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCTMXTiledMap *map = CCTMXTiledMap::create("TileMaps/orthogonal-test5.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
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();
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +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()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
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()
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCTMXTiledMap *map = CCTMXTiledMap::create("TileMaps/ortho-objects.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
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");
|
|
|
|
CCArray* objects = group->getObjects();
|
|
|
|
|
|
|
|
CCDictionary* dict = NULL;
|
|
|
|
CCObject* pObj = NULL;
|
|
|
|
CCARRAY_FOREACH(objects, pObj)
|
|
|
|
{
|
|
|
|
dict = (CCDictionary*)pObj;//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);
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMXOrthoObjectsTest::draw()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCTMXTiledMap* map = (CCTMXTiledMap*) getChildByTag(kTagTileMap);
|
|
|
|
CCTMXObjectGroup* group = map->objectGroupNamed("Object Group 1");
|
|
|
|
|
|
|
|
CCArray* objects = group->getObjects();
|
|
|
|
CCDictionary* dict = NULL;
|
|
|
|
CCObject* pObj = NULL;
|
|
|
|
CCARRAY_FOREACH(objects, pObj)
|
|
|
|
{
|
|
|
|
dict = (CCDictionary*)pObj;//dynamic_cast<CCStringToStringDictionary*>(*it);
|
|
|
|
|
|
|
|
if(!dict)
|
|
|
|
break;
|
|
|
|
const char* key = "x";
|
|
|
|
int x = ((CCString*)dict->objectForKey(key))->intValue();
|
|
|
|
key = "y";
|
|
|
|
int y = ((CCString*)dict->objectForKey(key))->intValue();//dynamic_cast<NSNumber*>(dict->objectForKey("y"))->getNumber();
|
|
|
|
key = "width";
|
|
|
|
int width = ((CCString*)dict->objectForKey(key))->intValue();//dynamic_cast<NSNumber*>(dict->objectForKey("width"))->getNumber();
|
|
|
|
key = "height";
|
|
|
|
int height = ((CCString*)dict->objectForKey(key))->intValue();//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);
|
|
|
|
}
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoObjectsTest::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "TMX Ortho object test";
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoObjectsTest::subtitle()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
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()
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCTMXTiledMap* map = CCTMXTiledMap::create("TileMaps/iso-test-objectgroup.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(map, -1, kTagTileMap);
|
|
|
|
|
|
|
|
CCSize s = map->getContentSize();
|
|
|
|
////----UXLOG("ContentSize: %f, %f", s.width,s.height);
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCTMXObjectGroup* group = map->objectGroupNamed("Object Group 1");
|
2010-11-18 14:50:28 +08:00
|
|
|
|
|
|
|
//UxMutableArray* objects = group->objects();
|
2012-04-19 14:35:52 +08:00
|
|
|
CCArray* objects = group->getObjects();
|
|
|
|
//UxMutableDictionary<std::string>* dict;
|
2012-03-20 15:04:53 +08:00
|
|
|
CCDictionary* dict;
|
2012-04-19 14:35:52 +08:00
|
|
|
CCObject* pObj = NULL;
|
|
|
|
CCARRAY_FOREACH(objects, pObj)
|
|
|
|
{
|
|
|
|
dict = (CCDictionary*)pObj;
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
if(!dict)
|
|
|
|
break;
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
////----UXLOG("object: %x", dict);
|
|
|
|
}
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMXIsoObjectsTest::draw()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCTMXTiledMap *map = (CCTMXTiledMap*) getChildByTag(kTagTileMap);
|
|
|
|
CCTMXObjectGroup *group = map->objectGroupNamed("Object Group 1");
|
|
|
|
|
|
|
|
CCArray* objects = group->getObjects();
|
|
|
|
CCDictionary* dict;
|
|
|
|
CCObject* pObj = NULL;
|
|
|
|
CCARRAY_FOREACH(objects, pObj)
|
|
|
|
{
|
|
|
|
dict = (CCDictionary*)pObj;//dynamic_cast<CCStringToStringDictionary*>(*it);
|
|
|
|
|
|
|
|
if(!dict)
|
|
|
|
break;
|
|
|
|
const char* key = "x";
|
|
|
|
int x = ((CCString*)dict->objectForKey(key))->intValue();//dynamic_cast<NSNumber*>(dict->objectForKey("x"))->getNumber();
|
|
|
|
key = "y";
|
|
|
|
int y = ((CCString*)dict->objectForKey(key))->intValue();//dynamic_cast<NSNumber*>(dict->objectForKey("y"))->getNumber();
|
|
|
|
key = "width";
|
|
|
|
int width = ((CCString*)dict->objectForKey(key))->intValue();//dynamic_cast<NSNumber*>(dict->objectForKey("width"))->getNumber();
|
|
|
|
key = "height";
|
|
|
|
int height = ((CCString*)dict->objectForKey(key))->intValue();//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);
|
|
|
|
}
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXIsoObjectsTest::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "TMX Iso object test";
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXIsoObjectsTest::subtitle()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
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()
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCTMXTiledMap* map = CCTMXTiledMap::create("TileMaps/orthogonal-test5.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
|
|
|
CCSize s = map->getContentSize();
|
|
|
|
////----UXLOG("ContentSize: %f, %f", s.width,s.height);
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCTMXLayer* layer;
|
|
|
|
layer = map->layerNamed("Layer 0");
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
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 ) );
|
|
|
|
}
|
|
|
|
}
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXResizeTest::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "TMX resize test";
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXResizeTest::subtitle()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
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()
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCTMXTiledMap *map = CCTMXTiledMap::create("TileMaps/iso-test-zorder.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
2011-02-23 16:47:25 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCSize s = map->getContentSize();
|
|
|
|
CCLOG("ContentSize: %f, %f", s.width,s.height);
|
2011-02-23 16:47:25 +08:00
|
|
|
map->setPosition(ccp(-s.width/2,0));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
m_tamara = CCSprite::create(s_pPathSister1);
|
2012-04-19 14:35:52 +08:00
|
|
|
map->addChild(m_tamara, map->getChildren()->count() );
|
|
|
|
m_tamara->retain();
|
|
|
|
int mapWidth = map->getMapSize().width * map->getTileSize().width;
|
|
|
|
m_tamara->setPosition(CC_POINT_PIXELS_TO_POINTS(ccp( mapWidth/2,0)));
|
|
|
|
m_tamara->setAnchorPoint(ccp(0.5f,0));
|
|
|
|
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCActionInterval* move = CCMoveBy::create(10, ccp(300,250));
|
2012-04-19 14:35:52 +08:00
|
|
|
CCActionInterval* back = move->reverse();
|
2012-12-10 14:12:56 +08:00
|
|
|
CCSequence* seq = CCSequence::create(move, back,NULL);
|
|
|
|
m_tamara->runAction( CCRepeatForever::create(seq) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
schedule( schedule_selector(TMXIsoZorder::repositionSprite) );
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TMXIsoZorder::~TMXIsoZorder()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
m_tamara->release();
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMXIsoZorder::onExit()
|
|
|
|
{
|
|
|
|
unschedule(schedule_selector(TMXIsoZorder::repositionSprite));
|
2012-04-19 14:35:52 +08:00
|
|
|
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
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCPoint p = m_tamara->getPosition();
|
|
|
|
p = CC_POINT_POINTS_TO_PIXELS(p);
|
|
|
|
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);
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXIsoZorder::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "TMX Iso Zorder";
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXIsoZorder::subtitle()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
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()
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCTMXTiledMap *map = CCTMXTiledMap::create("TileMaps/orthogonal-test-zorder.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
|
|
|
CCSize s = map->getContentSize();
|
|
|
|
////----UXLOG("ContentSize: %f, %f", s.width,s.height);
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
m_tamara = CCSprite::create(s_pPathSister1);
|
2012-04-19 14:35:52 +08:00
|
|
|
map->addChild(m_tamara, map->getChildren()->count());
|
|
|
|
m_tamara->retain();
|
|
|
|
m_tamara->setAnchorPoint(ccp(0.5f,0));
|
|
|
|
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCActionInterval* move = CCMoveBy::create(10, ccp(400,450));
|
2012-04-19 14:35:52 +08:00
|
|
|
CCActionInterval* back = move->reverse();
|
2012-12-10 14:12:56 +08:00
|
|
|
CCSequence* seq = CCSequence::create(move, back,NULL);
|
|
|
|
m_tamara->runAction( CCRepeatForever::create(seq));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
schedule( schedule_selector(TMXOrthoZorder::repositionSprite));
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TMXOrthoZorder::~TMXOrthoZorder()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
m_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
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCPoint p = m_tamara->getPosition();
|
|
|
|
p = CC_POINT_POINTS_TO_PIXELS(p);
|
|
|
|
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
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2012-04-19 14:35:52 +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
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
map->reorderChild(m_tamara, newZ);
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoZorder::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "TMX Ortho Zorder";
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoZorder::subtitle()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
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()
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCTMXTiledMap *map = CCTMXTiledMap::create("TileMaps/iso-test-vertexz.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
|
|
|
CCSize s = map->getContentSize();
|
2011-02-23 16:47:25 +08:00
|
|
|
map->setPosition( ccp(-s.width/2,0) );
|
2012-04-19 14:35:52 +08:00
|
|
|
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 CCSprite and it will work OK.
|
|
|
|
CCTMXLayer* layer = map->layerNamed("Trees");
|
|
|
|
m_tamara = layer->tileAt( ccp(29,29) );
|
|
|
|
m_tamara->retain();
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCActionInterval* move = CCMoveBy::create(10, ccpMult( ccp(300,250), 1/CC_CONTENT_SCALE_FACTOR() ) );
|
2012-04-19 14:35:52 +08:00
|
|
|
CCActionInterval* back = move->reverse();
|
2012-12-10 14:12:56 +08:00
|
|
|
CCSequence* seq = CCSequence::create(move, back,NULL);
|
|
|
|
m_tamara->runAction( CCRepeatForever::create(seq) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
schedule( schedule_selector(TMXIsoVertexZ::repositionSprite));
|
|
|
|
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TMXIsoVertexZ::~TMXIsoVertexZ()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
m_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
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// tile height is 64x32
|
|
|
|
// map size: 30x30
|
|
|
|
CCPoint p = m_tamara->getPosition();
|
|
|
|
p = CC_POINT_POINTS_TO_PIXELS(p);
|
|
|
|
float newZ = -(p.y+32) /16;
|
|
|
|
m_tamara->setVertexZ( newZ );
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMXIsoVertexZ::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
TileDemo::onEnter();
|
|
|
|
|
|
|
|
// TIP: 2d projection should be used
|
|
|
|
CCDirector::sharedDirector()->setProjection(kCCDirectorProjection2D);
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMXIsoVertexZ::onExit()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// At exit use any other projection.
|
|
|
|
// CCDirector::sharedDirector()->setProjection:kCCDirectorProjection3D);
|
|
|
|
TileDemo::onExit();
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXIsoVertexZ::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "TMX Iso VertexZ";
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXIsoVertexZ::subtitle()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
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()
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCTMXTiledMap *map = CCTMXTiledMap::create("TileMaps/orthogonal-test-vertexz.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
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));
|
2012-03-23 10:26:36 +08:00
|
|
|
CCLOG("%p vertexZ: %f", m_tamara, m_tamara->getVertexZ());
|
2012-04-19 14:35:52 +08:00
|
|
|
m_tamara->retain();
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCActionInterval* move = CCMoveBy::create(10, ccpMult( ccp(400,450), 1/CC_CONTENT_SCALE_FACTOR()));
|
2012-04-19 14:35:52 +08:00
|
|
|
CCActionInterval* back = move->reverse();
|
2012-12-10 14:12:56 +08:00
|
|
|
CCSequence* seq = CCSequence::create(move, back,NULL);
|
|
|
|
m_tamara->runAction( CCRepeatForever::create(seq));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
schedule(schedule_selector(TMXOrthoVertexZ::repositionSprite));
|
|
|
|
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TMXOrthoVertexZ::~TMXOrthoVertexZ()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
m_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
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// tile height is 101x81
|
|
|
|
// map size: 12x12
|
|
|
|
CCPoint p = m_tamara->getPosition();
|
|
|
|
p = CC_POINT_POINTS_TO_PIXELS(p);
|
|
|
|
m_tamara->setVertexZ( -( (p.y+81) /81) );
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMXOrthoVertexZ::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
TileDemo::onEnter();
|
|
|
|
|
|
|
|
// TIP: 2d projection should be used
|
|
|
|
CCDirector::sharedDirector()->setProjection(kCCDirectorProjection2D);
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMXOrthoVertexZ::onExit()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// At exit use any other projection.
|
|
|
|
// CCDirector::sharedDirector()->setProjection:kCCDirectorProjection3D);
|
|
|
|
TileDemo::onExit();
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoVertexZ::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "TMX Ortho vertexZ";
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoVertexZ::subtitle()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
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()
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCTMXTiledMap* map = CCTMXTiledMap::create("TileMaps/iso-test-movelayer.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
|
|
|
map->setPosition(ccp(-700,-50));
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCSize s = map->getContentSize();
|
|
|
|
////----UXLOG("ContentSize: %f, %f", s.width,s.height);
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXIsoMoveLayer::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "TMX Iso Move Layer";
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXIsoMoveLayer::subtitle()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
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()
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCTMXTiledMap *map = CCTMXTiledMap::create("TileMaps/orthogonal-test-movelayer.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCSize s = map->getContentSize();
|
|
|
|
////----UXLOG("ContentSize: %f, %f", s.width,s.height);
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoMoveLayer::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "TMX Ortho Move Layer";
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoMoveLayer::subtitle()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Trees should be horizontally aligned";
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
2012-03-26 16:46:23 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXTilePropertyTest
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2012-04-08 14:16:29 +08:00
|
|
|
|
|
|
|
TMXTilePropertyTest::TMXTilePropertyTest()
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCTMXTiledMap *map = CCTMXTiledMap::create("TileMaps/ortho-tile-property.tmx");
|
2012-04-08 14:16:29 +08:00
|
|
|
addChild(map ,0 ,kTagTileMap);
|
|
|
|
|
|
|
|
for(int i=1;i<=20;i++){
|
|
|
|
CCLog("GID:%i, Properties:%p", i, map->propertiesForGID(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-26 16:46:23 +08:00
|
|
|
std::string TMXTilePropertyTest::title()
|
2012-04-08 14:16:29 +08:00
|
|
|
{
|
|
|
|
return "TMX Tile Property Test";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXTilePropertyTest::subtitle()
|
|
|
|
{
|
|
|
|
return "In the console you should see tile properties";
|
|
|
|
}
|
|
|
|
|
2012-03-26 16:46:23 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXOrthoFlipTest
|
|
|
|
//
|
2012-04-08 14:16:29 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
TMXOrthoFlipTest::TMXOrthoFlipTest()
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCTMXTiledMap *map = CCTMXTiledMap::create("TileMaps/ortho-rotation-test.tmx");
|
2012-04-08 14:16:29 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
|
|
|
CCSize s = map->getContentSize();
|
|
|
|
CCLog("ContentSize: %f, %f", s.width,s.height);
|
|
|
|
|
|
|
|
CCObject* pObj = NULL;
|
|
|
|
CCARRAY_FOREACH(map->getChildren(), pObj)
|
|
|
|
{
|
|
|
|
CCSpriteBatchNode* child = (CCSpriteBatchNode*)pObj;
|
|
|
|
child->getTexture()->setAntiAliasTexParameters();
|
|
|
|
}
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCScaleBy* action = CCScaleBy::create(2, 0.5f);
|
2012-04-08 14:16:29 +08:00
|
|
|
map->runAction(action);
|
|
|
|
}
|
|
|
|
|
2012-03-26 16:46:23 +08:00
|
|
|
std::string TMXOrthoFlipTest::title()
|
2012-04-08 14:16:29 +08:00
|
|
|
{
|
|
|
|
return "TMX tile flip test";
|
|
|
|
}
|
|
|
|
|
2012-03-26 16:46:23 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXOrthoFlipRunTimeTest
|
|
|
|
//
|
2012-04-08 14:16:29 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
TMXOrthoFlipRunTimeTest::TMXOrthoFlipRunTimeTest()
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCTMXTiledMap *map = CCTMXTiledMap::create("TileMaps/ortho-rotation-test.tmx");
|
2012-04-08 14:16:29 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
|
|
|
CCSize s = map->getContentSize();
|
|
|
|
CCLog("ContentSize: %f, %f", s.width,s.height);
|
|
|
|
|
|
|
|
CCObject* pObj = NULL;
|
|
|
|
CCARRAY_FOREACH(map->getChildren(), pObj)
|
|
|
|
{
|
|
|
|
CCSpriteBatchNode* child = (CCSpriteBatchNode*)pObj;
|
|
|
|
child->getTexture()->setAntiAliasTexParameters();
|
|
|
|
}
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCScaleBy* action = CCScaleBy::create(2, 0.5f);
|
2012-04-08 14:16:29 +08:00
|
|
|
map->runAction(action);
|
|
|
|
|
|
|
|
schedule(schedule_selector(TMXOrthoFlipRunTimeTest::flipIt), 1.0f);
|
|
|
|
}
|
|
|
|
|
2012-03-26 16:46:23 +08:00
|
|
|
std::string TMXOrthoFlipRunTimeTest::title()
|
2012-04-08 14:16:29 +08:00
|
|
|
{
|
|
|
|
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)
|
2012-04-08 14:16:29 +08:00
|
|
|
{
|
|
|
|
CCTMXTiledMap *map = (CCTMXTiledMap*) getChildByTag(kTagTileMap);
|
|
|
|
CCTMXLayer *layer = map->layerNamed("Layer 0");
|
|
|
|
|
|
|
|
//blue diamond
|
|
|
|
CCPoint tileCoord = ccp(1,10);
|
|
|
|
int flags;
|
|
|
|
unsigned int GID = layer->tileGIDAt(tileCoord, (ccTMXTileFlags*)&flags);
|
|
|
|
// Vertical
|
|
|
|
if( flags & kCCTMXTileVerticalFlag )
|
|
|
|
flags &= ~kCCTMXTileVerticalFlag;
|
|
|
|
else
|
|
|
|
flags |= kCCTMXTileVerticalFlag;
|
|
|
|
layer->setTileGID(GID ,tileCoord, (ccTMXTileFlags)flags);
|
|
|
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
tileCoord = ccp(1,8);
|
2012-04-08 14:16:29 +08:00
|
|
|
GID = layer->tileGIDAt(tileCoord, (ccTMXTileFlags*)&flags);
|
|
|
|
// Vertical
|
|
|
|
if( flags & kCCTMXTileVerticalFlag )
|
|
|
|
flags &= ~kCCTMXTileVerticalFlag;
|
|
|
|
else
|
2012-04-19 14:35:52 +08:00
|
|
|
flags |= kCCTMXTileVerticalFlag;
|
2012-04-08 14:16:29 +08:00
|
|
|
layer->setTileGID(GID ,tileCoord, (ccTMXTileFlags)flags);
|
|
|
|
|
|
|
|
|
|
|
|
tileCoord = ccp(2,8);
|
|
|
|
GID = layer->tileGIDAt(tileCoord, (ccTMXTileFlags*)&flags);
|
|
|
|
// Horizontal
|
|
|
|
if( flags & kCCTMXTileHorizontalFlag )
|
|
|
|
flags &= ~kCCTMXTileHorizontalFlag;
|
|
|
|
else
|
2012-04-19 14:35:52 +08:00
|
|
|
flags |= kCCTMXTileHorizontalFlag;
|
|
|
|
layer->setTileGID(GID, tileCoord, (ccTMXTileFlags)flags);
|
2012-04-08 14:16:29 +08:00
|
|
|
}
|
2012-03-26 16:46:23 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXOrthoFromXMLTest
|
|
|
|
//
|
2012-04-08 14:16:29 +08:00
|
|
|
//------------------------------------------------------------------
|
2012-03-26 16:46:23 +08:00
|
|
|
|
|
|
|
TMXOrthoFromXMLTest::TMXOrthoFromXMLTest()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
string resources = "TileMaps"; // partial paths are OK as resource paths.
|
2012-04-08 14:16:29 +08:00
|
|
|
string file = resources + "/orthogonal-test1.tmx";
|
|
|
|
|
2012-06-27 17:08:50 +08:00
|
|
|
CCString* str = CCString::createWithContentsOfFile(CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(file.c_str()));
|
2012-04-08 14:16:29 +08:00
|
|
|
CCAssert(str != NULL, "Unable to open file");
|
|
|
|
|
2012-07-23 22:49:11 +08:00
|
|
|
CCTMXTiledMap *map = CCTMXTiledMap::createWithXML(str->getCString() ,resources.c_str());
|
2012-04-08 14:16:29 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
|
|
|
CCSize s = map->getContentSize();
|
|
|
|
CCLog("ContentSize: %f, %f", s.width,s.height);
|
|
|
|
|
|
|
|
CCObject* pObj = NULL;
|
|
|
|
CCARRAY_FOREACH(map->getChildren(), pObj)
|
|
|
|
{
|
|
|
|
CCSpriteBatchNode* child = (CCSpriteBatchNode*)pObj;
|
|
|
|
child->getTexture()->setAntiAliasTexParameters();
|
|
|
|
}
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCScaleBy* action = CCScaleBy::create(2, 0.5f);
|
2012-03-26 16:46:23 +08:00
|
|
|
map->runAction(action);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoFromXMLTest::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "TMX created from XML test";
|
2012-03-26 16:46:23 +08:00
|
|
|
}
|
|
|
|
|
2011-02-23 16:47:25 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXBug987
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2011-05-12 10:52:10 +08:00
|
|
|
TMXBug987::TMXBug987()
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCTMXTiledMap *map = CCTMXTiledMap::create("TileMaps/orthogonal-test6.tmx");
|
2011-05-12 10:52:10 +08:00
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
2011-02-23 16:47:25 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXBug787
|
|
|
|
//
|
2011-05-12 10:52:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
TMXBug787::TMXBug787()
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCTMXTiledMap *map = CCTMXTiledMap::create("TileMaps/iso-test-bug787.tmx");
|
2011-05-12 10:52:10 +08:00
|
|
|
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
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
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;
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
#define MAX_LAYER 28
|
2010-09-01 17:30:51 +08:00
|
|
|
|
|
|
|
CCLayer* createTileMapLayer(int nIndex)
|
|
|
|
{
|
2012-04-19 14:35:52 +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();
|
2012-04-08 14:16:29 +08:00
|
|
|
case 20: return new TMXOrthoFlipTest();
|
|
|
|
case 21: return new TMXOrthoFlipRunTimeTest();
|
2012-03-26 16:46:23 +08:00
|
|
|
case 22: return new TMXOrthoFromXMLTest();
|
2012-04-19 14:35:52 +08:00
|
|
|
case 23: return new TileMapTest();
|
|
|
|
case 24: return new TileMapEditTest();
|
2012-03-26 16:46:23 +08:00
|
|
|
case 25: return new TMXBug987();
|
|
|
|
case 26: return new TMXBug787();
|
2012-04-19 14:35:52 +08:00
|
|
|
case 27: return new TMXGIDObjectsTest();
|
|
|
|
}
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return NULL;
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CCLayer* nextTileMapAction()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
sceneIdx++;
|
|
|
|
sceneIdx = sceneIdx % MAX_LAYER;
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCLayer* pLayer = createTileMapLayer(sceneIdx);
|
|
|
|
pLayer->autorelease();
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return pLayer;
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CCLayer* backTileMapAction()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
sceneIdx--;
|
|
|
|
int total = MAX_LAYER;
|
|
|
|
if( sceneIdx < 0 )
|
|
|
|
sceneIdx += total;
|
|
|
|
|
|
|
|
CCLayer* pLayer = createTileMapLayer(sceneIdx);
|
|
|
|
pLayer->autorelease();
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return pLayer;
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CCLayer* restartTileMapAction()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCLayer* pLayer = createTileMapLayer(sceneIdx);
|
|
|
|
pLayer->autorelease();
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return pLayer;
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TileDemo::TileDemo(void)
|
|
|
|
{
|
2012-06-15 15:10:40 +08:00
|
|
|
setTouchEnabled( true );
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
m_label = CCLabelTTF::create("", "Arial", 28);
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(m_label, 1);
|
|
|
|
m_label->setPosition( ccp(s.width/2, s.height-50) );
|
|
|
|
m_label->retain();
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
std::string strSubtitle = subtitle();
|
|
|
|
if( ! strSubtitle.empty() )
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCLabelTTF* l = CCLabelTTF::create(strSubtitle.c_str(), "Thonburi", 16);
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(l, 1);
|
|
|
|
l->setPosition( ccp(s.width/2, s.height-80) );
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_subtitle = l;
|
|
|
|
m_subtitle->retain();
|
|
|
|
}
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenuItemImage *item1 = CCMenuItemImage::create(s_pPathB1, s_pPathB2, this, menu_selector(TileDemo::backCallback) );
|
|
|
|
CCMenuItemImage *item2 = CCMenuItemImage::create(s_pPathR1, s_pPathR2, this, menu_selector(TileDemo::restartCallback) );
|
|
|
|
CCMenuItemImage *item3 = CCMenuItemImage::create(s_pPathF1, s_pPathF2, this, menu_selector(TileDemo::nextCallback) );
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenu *menu = CCMenu::create(item1, item2, item3, NULL);
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
menu->setPosition( CCPointZero );
|
2012-10-23 17:48:50 +08:00
|
|
|
item1->setPosition(ccp(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));
|
|
|
|
item2->setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2));
|
|
|
|
item3->setPosition(ccp(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
addChild(menu, 1);
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TileDemo::~TileDemo(void)
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
m_label->release();
|
|
|
|
m_subtitle->release();
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
2010-09-01 17:30:51 +08:00
|
|
|
std::string TileDemo::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "No title";
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TileDemo::subtitle()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "drag the screen";
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TileDemo::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCLayer::onEnter();
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_label->setString(title().c_str());
|
|
|
|
m_subtitle->setString(subtitle().c_str());
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
void TileDemo::restartCallback(CCObject* pSender)
|
2010-09-01 17:30:51 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCScene* s = new TileMapTestScene();
|
|
|
|
s->addChild(restartTileMapAction());
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCDirector::sharedDirector()->replaceScene(s);
|
|
|
|
s->release();
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
void TileDemo::nextCallback(CCObject* pSender)
|
2010-09-01 17:30:51 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCScene* s = new TileMapTestScene();
|
|
|
|
s->addChild( nextTileMapAction() );
|
|
|
|
CCDirector::sharedDirector()->replaceScene(s);
|
|
|
|
s->release();
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
void TileDemo::backCallback(CCObject* pSender)
|
2010-09-01 17:30:51 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCScene* s = new TileMapTestScene();
|
|
|
|
s->addChild( backTileMapAction() );
|
|
|
|
CCDirector::sharedDirector()->replaceScene(s);
|
|
|
|
s->release();
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2012-11-19 16:28:37 +08:00
|
|
|
void TileDemo::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent)
|
2010-09-01 17:30:51 +08:00
|
|
|
{
|
2012-11-19 16:28:37 +08:00
|
|
|
CCTouch *touch = (CCTouch*)pTouches->anyObject();
|
|
|
|
|
2012-07-31 17:41:53 +08:00
|
|
|
CCPoint diff = touch->getDelta();
|
2012-04-19 14:35:52 +08:00
|
|
|
CCNode *node = getChildByTag(kTagTileMap);
|
|
|
|
CCPoint currentPos = node->getPosition();
|
|
|
|
node->setPosition( ccpAdd(currentPos, diff) );
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TileMapTestScene::runThisTest()
|
|
|
|
{
|
|
|
|
CCLayer* pLayer = nextTileMapAction();
|
|
|
|
addChild(pLayer);
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// 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);
|
|
|
|
|
2010-11-18 14:50:28 +08:00
|
|
|
CCDirector::sharedDirector()->replaceScene(this);
|
|
|
|
}
|
2011-07-06 14:56:05 +08:00
|
|
|
|
2011-07-12 14:21:29 +08:00
|
|
|
TMXGIDObjectsTest::TMXGIDObjectsTest()
|
2011-07-06 14:56:05 +08:00
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCTMXTiledMap *map = CCTMXTiledMap::create("TileMaps/test-object-layer.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(map, -1, kTagTileMap);
|
2011-07-06 14:56:05 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCSize s = map->getContentSize();
|
|
|
|
CCLOG("Contentsize: %f, %f", s.width, s.height);
|
2011-07-06 14:56:05 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCLOG("----> Iterating over all the group objets");
|
|
|
|
//CCTMXObjectGroup *group = map->objectGroupNamed("Object Layer 1");
|
2011-07-06 14:56:05 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-07-12 14:21:29 +08:00
|
|
|
void TMXGIDObjectsTest::draw()
|
2011-07-06 14:56:05 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCTMXTiledMap *map = (CCTMXTiledMap*)getChildByTag(kTagTileMap);
|
|
|
|
CCTMXObjectGroup *group = map->objectGroupNamed("Object Layer 1");
|
2011-07-06 14:56:05 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCArray *array = group->getObjects();
|
|
|
|
CCDictionary* dict;
|
|
|
|
CCObject* pObj = NULL;
|
|
|
|
CCARRAY_FOREACH(array, pObj)
|
|
|
|
{
|
|
|
|
dict = (CCDictionary*)pObj;
|
|
|
|
if(!dict)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* key = "x";
|
|
|
|
int x = ((CCString*)dict->objectForKey(key))->intValue();
|
|
|
|
key = "y";
|
|
|
|
int y = ((CCString*)dict->objectForKey(key))->intValue();
|
|
|
|
key = "width";
|
|
|
|
int width = ((CCString*)dict->objectForKey(key))->intValue();
|
|
|
|
key = "height";
|
|
|
|
int height = ((CCString*)dict->objectForKey(key))->intValue();
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2011-07-06 14:56:05 +08:00
|
|
|
}
|
|
|
|
|
2011-07-12 14:21:29 +08:00
|
|
|
string TMXGIDObjectsTest::title()
|
2011-07-06 14:56:05 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "TMX GID objects";
|
2011-07-06 14:56:05 +08:00
|
|
|
}
|
|
|
|
|
2011-07-12 14:21:29 +08:00
|
|
|
string TMXGIDObjectsTest::subtitle()
|
2011-07-06 14:56:05 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Tiles are created from an object group";
|
2011-07-06 14:56:05 +08:00
|
|
|
}
|