由于CCTMXTiledMap 不支持读取polyline 需要修改引擎代码 CCTMXXMLPaerser.cpp(在CCTMXMapInfo类中)中CCTMXMapInfo::startElement函数
将
- else if (elementName == "polyline")
- {
- // find parent object's dict and add polyline-points to it
- // CCTMXObjectGroup* objectGroup = (CCTMXObjectGroup*)m_pObjectGroups->lastObject();
- // CCDictionary* dict = (CCDictionary*)objectGroup->getObjects()->lastObject();
- // TODO: dict->setObject:[attributeDict objectForKey:@"points"] forKey:@"polylinePoints"];
- }
修改为
- else if (elementName == "polyline")
- {
- // find parent object's dict and add polyline-points to it
- CCTMXObjectGroup* objectGroup = (CCTMXObjectGroup*)m_pObjectGroups->lastObject();
- CCDictionary* dict = (CCDictionary*)objectGroup->getObjects()->lastObject();
- // TODO: dict->setObject:[attributeDict objectForKey:@"points"] forKey:@"polylinePoints"];
- CCString* obj = new CCString(valueForKey("points", attributeDict));
- dict->setObject(obj, "polylinePoints");
- obj->autorelease();
- }
调用为
- CCTMXTiledMap *map=CCTMXTiledMap::create("test.tmx");
- this->addChild(map);
- CCTMXObjectGroup *objGroup = map->objectGroupNamed("obj");
- CCDictionary *road=objGroup->objectNamed("road");
- CCString* points = (CCString*)road->objectForKey("polylinePoints");
注:TMX文件里存的Y坐标是相对于左上角为原点的,而Cocos2d-x采用的是以左下角为原点的,所以CCTMXTiledMap取出来的Y坐标跟TMX文件中的Y坐标不一样