My version is 2.0rc when reading the properties of objectgroup appeared: http://www.cocos2d-x.org/boards/6/topics/13525? R = 13704 # problems mentioned in message-13704
The author raised the question that tinyxml can be used to solve the reading problem.
The following code is transferred:
if (pBuffer){ //Load data /////////////////////////////////////////////////////////////////////////////////////////////////// tinyxml2::XMLDocument doc; doc.Parse((const char*)pBuffer);tinyxml2::XMLElement* map = doc.FirstChildElement("map"); if ( map ){ tinyxml2::XMLElement* objects = map->FirstChildElement("objectgroup"); if ( objects ) { tinyxml2::XMLElement* firstChild = objects->FirstChildElement(); if ( firstChild ) { tinyxml2::XMLElement* nextChild = firstChild; while ( nextChild != NULL ) { std::string elementName = nextChild->Name(); if ( elementName == std::string("object") ) { onEntityElement(nextChild, scene); }nextChild = nextChild->NextSiblingElement(); } } } } /////////////////////////////////////////////////////////////////////////////////////////////////// }@@void MapLoader::onEntityElement(tinyxml2::XMLElement* object, cocos2d::CCLayer* scene) {//Position and typefloat x = object->FloatAttribute("x");float y = object->FloatAttribute("y");float width = object->FloatAttribute("width"); float height = object->FloatAttribute("height");//x = (x)-m_map->getMapSize().width*32; y = (y)+m_map>getMapSize().height*32;CCPoint pos = ccp(x,y);std::string type = object->Attribute("type");//Attributes std::vector<SObjectParam> params; tinyxml2::XMLElement* props = object->FirstChildElement("properties"); if ( props ){ tinyxml2::XMLElement* firstChild = props->FirstChildElement(); if ( firstChild ) { tinyxml2::XMLElement* nextChild = firstChild; while ( nextChild != NULL ) { if ( std::string(nextChild->Name()) == std::string("property") ) { SObjectParam param; param.m_name = nextChild->Attribute("name"); param.m_value = nextChild->Attribute("value"); params.push_back(param); }nextChild = nextChild->NextSiblingElement(); } } }//Create entity GameObject* obj = GameObjectFactory::createObject(type, pos, params, width, height); if ( obj ){ m_map->addChild(obj); }}@
However, we still hope that 2.0 can solve the problem of reading the XML objectgroup attribute being null because 1.01 reading is correct.