CCTMXTiledMap:
CCTMXTiledMap *pMap=CCTMXTiledMap::create("map.tmx");
CCTMXLayer * pLayer=map->layerName("Layer0");
//获取ID
CCPoint pt=ccp(5,6);
int id=tileGIDAt(pt);
//获取对象
CCTMXObjectGroup* pGroup = pMap->objectGroupName("object0");//获取对象层
CCArray* pObjects = pGroup ->getObjects();//获取层上对象集合
CCDictionary* pDict = NULL;
CCObject* pObj = NULL;
CCARRAY_FOREACH(pObjects, pObj)//遍历对象集合中的对象
{
pDict = (CCDictionary*)pObj;
if(!pDict)
break;
const char* key = "playerBorn";//设定关键字,对应我们的"playerBorn"
CCString *str = (CCString*)dict->objectForKey(key);
if(str)
{
key = "x";
float x = ((CCString*)dict->objectForKey(key))->floatValue();//获取对应对象的x坐标
key = "y";
float y = ((CCString*)dict->objectForKey(key))->floatValue();//获取对应对象的y坐标
player->setPosition(ccp(x,y));//这里player是我们的主角sprite对象,设置坐标位置
key = "hp";
int Hp = ((CCString*)dict->objectForKey(key))->intValue();//获得主角血量100
player->setHp(Hp);
break;//找到过后,退出循环
}
}
CCTMXTiledMap *m_pBubblesMap;//气泡砖块
CCTMXObjectGroup *m_pObjectGround;
CCDictionary *m_pPlayerPoint;
CCSprite *m_pPlayer;
m_pObjectGround=m_pBubblesMap->objectGroupNamed("Object");
m_pPlayerPoint=m_pObjectGround->objectNamed("Player");
float x=m_pPlayerPoint->valueForKey("x")->floatValue();
float y=m_pPlayerPoint->valueForKey("y")->floatValue();
m_pPlayer=CPlayer::create(pTex);
m_pPlayer->setPosition(ccp(x,y));
CCTileMapAtlas:
CCTileMapAtlas* map = CCTileMapAtlas::create(地图素材.png,地图数据.tga.,tile块宽,tile块高);
cocos2dx为了兼容性,所以保留了,现在cocos2dx不推荐使用此种方式拼图了..