cocos2dx 读取tilemap objectgroup 属性为空问题
2012-08-01 11:21
316 查看
我的版本是2.0rc 读取objectgroup 的属性的时候 出现了:http://www.cocos2d-x.org/boards/6/topics/13525?r=13704#message-13704 里面提到的问题
提问的楼主提出了 用tinyxml解决读取的问题 挺好的
这里转下他的代码:
不过还是希望 2.0能解决读取xml objectgroup 属性为空的问题 因为 1.01读取是没有问题的
提问的楼主提出了 用tinyxml解决读取的问题 挺好的
这里转下他的代码:
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 type float 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); } }@
不过还是希望 2.0能解决读取xml objectgroup 属性为空的问题 因为 1.01读取是没有问题的
相关文章推荐
- cocos2dx之砖块地图研究——TiledMap,CCTMXTiledMap,CCTMXLayer,CCTMXObjectGroup
- Mongo的morphia读取Map<String, List<Object>>类型数据的问题
- 读取属性文件时提示FileNotFound或路径查找不到时遇到的问题备忘
- ArcGIS9、MapObject2.2和ArcExplorer2.0连接ArcSDE9.0问题
- cocos2d-x TiledMap获取tiled属性:tiledID、旋转以及翻转信息
- 顺序从map中读取记录的问题
- 很有意思的Object对象属性读取
- python读取删除重写json以及遇见问题ValueError: No JSON object could be decoded
- 读取xml文件属性的问题
- 思考一个问题:如何将map里面的值,映射到一个对象里的属性,不通过手动方式设置!!!
- 解决Spring配置文件无法读取properties属性问题
- cocos2dx ios android 读取资源问题
- Fast TileMap ---Cocos2dx
- [Play with T]_[C# 类与属性操作] 通过克隆实现ObjectMap对List的填充
- 关于JSONObject to Map 数字太大被转成科学计数法的问题
- mybatis3.0x升级整合spring问题(读取不到properties文件属性)
- 问题:调用 ASP.Net Core WebAPI的HTTP POST方法时,从 [FromBody] 中读取的 MongoDB GeoJsonObjectModel成员总是null
- 关于VC单选按钮不能设置变量的问题以及Group属性的设置
- 在代码中,子view设置的属性在viewGroup中无效的问题解决
- 从数据库读取text属性数据,并比较内容是否相等的问题。