
简介
做游戏难免和各种图片和声音,pList打交道,在创建精灵和加载帧图片时,资源路径没有写对程序会崩掉的。往往这个路径错了,找问题原因去非常难找。看看自己写的代码有没有问题,可是就是不知道什么原因。写路径就比较麻烦了,路径写错了更麻烦了。对此,小弟我做了一个shell 脚本 来生成一个叫ResourcePath.h的文件来 “点” 出你要资源的路径。适合支持shell 脚本的系统。
效果如下:
资源归类有以下11种:
1.image(图片资源):jpg、jpeg、pvr、pvr.ccz、pvr.gz、tga;
2.pList(配置文件,图片配置文件,用户自定义配置文件):pList;
3.audio(音效,背景音乐):ogg、wave、WAV、mp3、MP3;
4.Font(字体):fnt、ttf;
5.tmx(地图):tmx;
6.xml(XML): xml;
7.Json(JsON):Json;
8.spine (SPINE骨骼动画文件):spine;
9.txt(TXT文本);txt;
10.shader(着色器):fsh、vsh;
11.ccb(CocosBuilder生成文件): ccbi;
用法非常简单
对了解AndroID的同学知道调用res文件下的资源文件是比较简单的。比如找到布局文件:
setContentVIEw(R.layout.cottom_dialog);
参考AndroID的形式在代码中用法类似。比如创建背景精灵:
Sprite* bg =Sprite::create(R.image.more_bg);
bg->setposition(Point(960,540));
this->addChild(bg,0);
如何生成Resource.h 文件
将makeResListtoc++.sh 放在Resources ,进入终端 运行一下makeResListtoc++.sh 生成的ResourcesPath.h 放在了Classes,如下图。
////// ResourcesPath.h// // Created by lili on 2014-09-30////#ifndef ResourcesPath_h#define ResourcesPath_hstatic struct Resourses{ struct Image{ std::string baozha = "flygame/baozha.png"; std::string p_zhuye = "public/pic/p_zhuye.png"; } image; struct PList{ std::string baozha = "flygame/baozha.pList"; std::string dangeres = "flygame/dangeres.pList"; std::string p_s5_0001 = "public/pic/p_s5_0001.pList"; } pList; struct Audio{ std::string s_bubble = "flygame/audio/s_bubble.mp3"; std::string s_bullet_bong = "flygame/audio/s_bullet_bong.wav"; std::string p_wind_en = "public/audio/s5/p_wind_en.mp3"; } audio; struct Font{ std::string arial = "Fonts/arial.ttf"; } Font; struct Json{ std::string appinfodata = "more/image/appinfodata.Json"; } Json;} R;#endif 如何得到makeResListtoc++.sh
传送门
GitHub:https://github.com/baibai2013/cocos2d-x-3.0-ResoucePath
总结以上是内存溢出为你收集整理的cocos2d-x3.0 资源路径生成脚本makeResListtoc++.sh 体验“点”出来的快感!全部内容,希望文章能够帮你解决cocos2d-x3.0 资源路径生成脚本makeResListtoc++.sh 体验“点”出来的快感!所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)