CCTMXObjectGroup 类对象图层的剖析CCDictionary

长平狐 发布于 2012/08/29 14:25
阅读 301
收藏 0

首先从地图文件里面获得对象组

CCTMXObjectGroup *objGroup = tmxMap->objectGroupNamed("object1");

 

api中提供了通过objectName 来获取每个CCDictionary对象

我们通过CCTMXObjectGroup 里的 getObjects() 取得这层对象的集合;

遍历这个集合 拿到每个对象的字典

CCTMXObjectGroup *objGroup = map_physical->tmxMap->objectGroupNamed("shan");
	CCArray *objArray = objGroup->getObjects();


	if (objArray && objArray->count() > 0)
	{
		CCObject* pObj = NULL;
		CCARRAY_FOREACH(objArray, pObj)
		{
			CCDictionary* spawnPoint = (CCDictionary*)pObj;

			CCDictElement *keyString = NULL;
			CCDICT_FOREACH(spawnPoint, keyString)
			{
				const char *xps =  keyString->getStrKey();
				CCLog("dict:key %s", xps);
				CCString  *xps1 =  (CCString *)(keyString->getObject());
				CCLog("dict:value %f", xps1->floatValue());
			}
		}
	}

 

每个对象字典中的格式输出如下:

 

dict:key name
dict:value 0.000000
dict:key type
dict:value 0.000000
dict:key width
dict:value 0.000000
dict:key height
dict:value 0.000000
dict:key gid
dict:value 147.000000
dict:key x
dict:value 965.000000
dict:key y
dict:value 1312.000000


ok 就到这儿吧


原文链接:http://blog.csdn.net/lwuit/article/details/7919873
加载中
返回顶部
顶部