Cocos2dx reading tilemap objectgroup attribute is empty

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.