Cocos2d-x游戏开发之TecturePacker的plist解析
先要做准备工作
先下载DS_Dictionary.h和Ds_Dictionary.cpp,不多说提供下载地址
http://www.cocos2d-x.org/boards/6/topics/6125?r=13203#message-13203
文件基于pugixml下面是下载地址
http://pugixml.org/
下面提供test.plist作对照
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEplistPUBLIC"-//Apple//DTDPLIST1.0//EN""http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plistversion="1.0"><dict><key>texture</key><dict><key>width</key><integer>512</integer><key>height</key><integer>1024</integer></dict><key>frames</key><dict><key>bg_0.png</key><dict><key>x</key><integer>1</integer><key>y</key><integer>289</integer><key>width</key><integer>480</integer><key>height</key><integer>287</integer><key>offsetX</key><real>0</real><key>offsetY</key><real>1</real><key>originalWidth</key><integer>480</integer><key>originalHeight</key><integer>289</integer></dict><key>bg_2.png</key><dict><key>x</key><integer>1</integer><key>y</key><integer>1</integer><key>width</key><integer>480</integer><key>height</key><integer>287</integer><key>offsetX</key><real>0</real><key>offsetY</key><real>0</real><key>originalWidth</key><integer>480</integer><key>originalHeight</key><integer>287</integer></dict><key>bg_1.png</key><dict><key>x</key><integer>1</integer><key>y</key><integer>577</integer><key>width</key><integer>480</integer><key>height</key><integer>287</integer><key>offsetX</key><real>0</real><key>offsetY</key><real>0</real><key>originalWidth</key><integer>480</integer><key>originalHeight</key><integer>287</integer></dict></dict></dict></plist>
下面提供一个解析的函数
voidcollision::plistParse(){//LoadrootDictfromfile,andthenstepintothemetadatasubdict.DS_DictionaryrootDict;if(!rootDict.loadRootSubDictFromFile(bgObjectPlist)){printf("noload\n");}if(!rootDict.stepIntoSubDictWithKey("texture")){printf("Notexture\n");}//GetanintvaluefromthesubdictintsomeInt=rootDict.getIntegerForKey("height");printf("height%d\n",someInt);someInt=rootDict.getIntegerForKey("width");printf("width%d\n",someInt);//StepoutofthesubdictandintoanotherrootDict.stepOutOfSubDict();if(!rootDict.stepIntoSubDictWithKey("frames")){printf("nodic\n");}for(inti=0;i<3;){charpicture[20];sprintf(picture,"bg_%d.png",i);if(!rootDict.stepIntoSubDictWithKey(picture)){i++;//printf("No%s\n",picture);rootDict.stepOutOfSubDict();continue;}intx=rootDict.getIntegerForKey("x");inty=rootDict.getIntegerForKey("y");intwidth=rootDict.getIntegerForKey("width");intheight=rootDict.getIntegerForKey("height");}voidstepBackToRootSubDict();}
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。