小羊驼和你一起学习cocos2d-x之八(tinyXml android cocos2d-x 2.x)
来源:互联网 发布:逆战辅助源码 编辑:程序博客网 时间:2024/04/27 20:16
http://blog.csdn.net/linyongliang
欢迎转载:请保留原文出处 谢谢
本次介绍如何在cocos2d-x上使用tinyXml库 对于tinyxml我不做多介绍,不懂朋友度娘 谷哥
tinyxml 在win32上是可以直接使用没啥问题。但是放到android上会出现路径找不到,这里就是要帮大家解决这个问题。其实这个代码是人家写的 我改了一点让2.X可 以使用。谢谢那位朋友 。具体出处忘了 真不好意思
其中引擎自带了一个解析器。里面是有文件路径获取方法的。那位朋友也是根据这个原来来修改tinyXml库
具体我吧代码弄上来,其实是给tinyXml加一个加载的成员函数 如下
bool TiXmlDocument::LoadFileByCocos2d( const char * filename, TiXmlEncoding encoding /*= TIXML_ENCODING_UTF8*/ ){if ( !filename ) {SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN );return false;}// Delete the existing data:Clear();location.Clear();// Get the file size, so we can pre-allocate the string. HUGE speed impact.const char *pfilePath = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(filename);TIXML_STRING __filename( pfilePath );value = __filename;unsigned long length = 0;char *pBuffer =(char*) CCFileUtils::sharedFileUtils()->getFileData(pfilePath, "rt", &length);if (!pBuffer){SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN );return false;}// Strange case, but good to handle up front.if ( length <= 0 ){SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN );return false;}const char* p = pBuffer;// the read headchar* q = pBuffer;// the write headconst char CR = 0x0d;const char LF = 0x0a;pBuffer[length] = 0;while( *p ) {assert( p < (pBuffer+length) );assert( q <= (pBuffer+length) );assert( q <= p );if ( *p == CR ) {*q++ = LF;p++;if ( *p == LF ) {// check for CR+LF (and skip LF)p++;}}else {*q++ = *p++;}}assert( q <= (pBuffer+length) );*q = 0;Parse( pBuffer, 0, encoding );return !Error();}bool TiXmlDocument::SaveFile( const char * filename ) const{// The old c stuff lives on...FILE* fp = TiXmlFOpen( filename, "w" );if ( fp ){bool result = SaveFile( fp );fclose( fp );return result;}return false;}//具体哪里加 自己找
bool loadConfig()//如何使用 简单个例子 自己看吧{bool ret=false;do {TiXmlDocument doc;TiXmlElement *elementRoot,*elementIndex,*elementLast,*elementChildIndex,*elementChildLast;TiXmlAttribute *attribute;int id;doc.LoadFileByCocos2d("config.xml");elementRoot=doc.FirstChildElement(); attribute=elementIndex->FirstAttribute();id=attribute->IntValue();vector<Point>vecPoint;elementChildIndex=elementIndex->FirstChildElement("vertex");elementChildLast=(TiXmlElement *)elementIndex->LastChild("vertex");while(elementChildIndex!=elementChildLast){attribute=elementChildIndex->FirstAttribute();point.x=attribute->IntValue();attribute=attribute->Next();point.y=attribute->IntValue();vecPoint.push_back(point);elementChildIndex=elementChildIndex->NextSiblingElement();}attribute=elementChildIndex->FirstAttribute();point.y=attribute->IntValue();attribute=attribute->Next();point.x=attribute->IntValue();vecPoint.push_back(point);mapArray.insert(map<int_16_u,vector<Point> >::value_type(id,vecPoint));doc.Clear();ret = true;} while (0);return ret;}
android的Android.mk配置LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)LOCAL_MODULE := game_sharedLOCAL_MODULE_FILENAME := libgameLOCAL_SRC_FILES := hellocpp/main.cpp \ ../../Classes/AppDelegate.cpp \ ../../Classes/SceneGreet.cpp \ ../../Classes/SceneSet.cpp \ ../../Classes/ScenePlay.cpp \ ../../Classes/Bullet.cpp \ ../../Classes/Fish.cpp \ ../../Classes/tinyxml.cpp \ ../../Classes/tinystr.cpp \ ../../Classes/tinyxmlparser.cpp \ ../../Classes/tinyxmlerror.cpp \ ../../Classes/Config.cpp \ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocosdenshion_static cocos_extension_static include $(BUILD_SHARED_LIBRARY)$(call import-module,CocosDenshion/android) \$(call import-module,cocos2dx) \$(call import-module,extensions)
- 小羊驼和你一起学习cocos2d-x之八(tinyXml android cocos2d-x 2.x)
- 小羊驼和你一起学习cocos2d-x之六(lua、android.mk)
- 小羊驼和你一起学习cocos2d-x与lua之五(lua编写cocos2d-x游戏)
- 小羊驼和你一起学习cocos2d-x与lua之六(lua编写cocos2d-x注意事项)
- 小羊驼和你一起学习cocos2d-x与lua之四(泛型for学习)
- 小羊驼和你一起学习cocos2d-x与lua之二(表达式特殊写法)
- 小羊驼和你一起学习cocos2d-x与lua之三(lua匿名函数)
- 小羊驼和你一起学习cocos2d-x之三(进度条、CCProgressTimer)
- 小羊驼和你一起学习cocos2d-x之四(摇杆)
- 小羊驼和你一起学习cocos2d-x之五(结合摇杆控制玩家走动)
- 小羊驼和你一起学习cocos2d-x与lua之五(HelloLua分析)
- 小羊驼和你一起学习cocos2d-x与lua之一(迭代器pairs 和 ipairs区别)
- 小羊驼和你一起学习cocos2d-x之一(异步加载资源利用addImageAsync)
- 小羊驼和你一起学习cocos2d-x之二(屏幕匹配、多分辨率解决方案、分辨率适配)
- 小羊驼和你一起学习cocos2d-x与lua之零(lua教程 高清无码你懂 请好评吧 绝对极品)
- cocos2d-x 配置 tinyxml 库
- cocos2d-x和Android学习思考
- cocos2d-x 3.x学习之SpriteFrameCache
- vs2008\drivers\opengl_3.h.c_opengl显示24位BMP图像简介+示例
- VRML,图形引擎, OpenGL,WebGL
- JSP/SERVLET入门教程--Servlet 使用入门
- Java程序员从笨鸟到菜鸟之(一)开发环境搭建,基本语法,字符串,数组
- 井型与井别的区别
- 小羊驼和你一起学习cocos2d-x之八(tinyXml android cocos2d-x 2.x)
- 汇编基础知识
- Cookie
- SSO学习 -- CAS服务器端的配置
- win32创建控件的一些问题
- mysql之路的反思
- X模型文件格式简介
- 11、过滤器Filter
- 避免遮掩继承而来的名称