温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Cocos2d-x游戏开发之TecturePacker的plist解析

发布时间:2020-06-19 17:17:12 来源:网络 阅读:2535 作者:lonag 栏目:开发技术

 先要做准备工作

先下载DS_Dictionary.hDs_Dictionary.cpp,不多说提供下载地址

http://www.cocos2d-x.org/boards/6/topics/6125?r=13203#message-13203

文件基于pugixml下面是下载地址

http://pugixml.org/

 

下面提供test.plist作对照

 

  1. <?xml version="1.0" encoding="UTF-8"?> 
  2. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
  3. <plist version="1.0"> 
  4. <dict> 
  5.     <key>texture</key> 
  6.     <dict> 
  7.         <key>width</key> 
  8.         <integer>512</integer> 
  9.         <key>height</key> 
  10.         <integer>1024</integer> 
  11.     </dict> 
  12.     <key>frames</key> 
  13.     <dict> 
  14.         <key>bg_0.png</key> 
  15.         <dict> 
  16.             <key>x</key> 
  17.             <integer>1</integer> 
  18.             <key>y</key> 
  19.             <integer>289</integer> 
  20.             <key>width</key> 
  21.             <integer>480</integer> 
  22.             <key>height</key> 
  23.             <integer>287</integer> 
  24.             <key>offsetX</key> 
  25.             <real>0</real> 
  26.             <key>offsetY</key> 
  27.             <real>1</real> 
  28.             <key>originalWidth</key> 
  29.             <integer>480</integer> 
  30.             <key>originalHeight</key> 
  31.             <integer>289</integer> 
  32.         </dict> 
  33.         <key>bg_2.png</key> 
  34.         <dict> 
  35.             <key>x</key> 
  36.             <integer>1</integer> 
  37.             <key>y</key> 
  38.             <integer>1</integer> 
  39.             <key>width</key> 
  40.             <integer>480</integer> 
  41.             <key>height</key> 
  42.             <integer>287</integer> 
  43.             <key>offsetX</key> 
  44.             <real>0</real> 
  45.             <key>offsetY</key> 
  46.             <real>0</real> 
  47.             <key>originalWidth</key> 
  48.             <integer>480</integer> 
  49.             <key>originalHeight</key> 
  50.             <integer>287</integer> 
  51.         </dict> 
  52.         <key>bg_1.png</key> 
  53.         <dict> 
  54.             <key>x</key> 
  55.             <integer>1</integer> 
  56.             <key>y</key> 
  57.             <integer>577</integer> 
  58.             <key>width</key> 
  59.             <integer>480</integer> 
  60.             <key>height</key> 
  61.             <integer>287</integer> 
  62.             <key>offsetX</key> 
  63.             <real>0</real> 
  64.             <key>offsetY</key> 
  65.             <real>0</real> 
  66.             <key>originalWidth</key> 
  67.             <integer>480</integer> 
  68.             <key>originalHeight</key> 
  69.             <integer>287</integer> 
  70.         </dict> 
  71.     </dict> 
  72. </dict> 
  73. </plist> 

下面提供一个解析的函数

 

  1. void collision::plistParse() 
  2.     //Load rootDict from file, and then step into the metadata sub dict. 
  3.     DS_Dictionary rootDict; 
  4.     if(!rootDict.loadRootSubDictFromFile(bgObjectPlist)) 
  5.     {  
  6.             printf("no load\n");  
  7.     } 
  8.     if(!rootDict.stepIntoSubDictWithKey("texture")) 
  9.     {  
  10.            printf("No texture\n");  
  11.     } 
  12.     //Get an int value from the subdict 
  13.     int someInt = rootDict.getIntegerForKey("height"); 
  14.  
  15.     printf("height    %d\n",someInt); 
  16.  
  17.     someInt = rootDict.getIntegerForKey("width"); 
  18.  
  19.     printf("width    %d\n",someInt); 
  20.     //Step out of the sub dict and into another 
  21.     rootDict.stepOutOfSubDict(); 
  22.  
  23.     if(!rootDict.stepIntoSubDictWithKey("frames")) 
  24.     { 
  25.             printf("no dic\n");  
  26.     } 
  27.     for(int i=0;i<3;) 
  28.     { 
  29.         char picture[20]; 
  30.         sprintf(picture,"bg_%d.png",i); 
  31.         if(!rootDict.stepIntoSubDictWithKey(picture)) 
  32.         { 
  33.             i++; 
  34.             //printf("No    %s\n",picture); 
  35.             rootDict.stepOutOfSubDict(); 
  36.             continue
  37.         } 
  38.         int x=rootDict.getIntegerForKey("x"); 
  39.         int y=rootDict.getIntegerForKey("y"); 
  40.         int width=rootDict.getIntegerForKey("width"); 
  41.         int height=rootDict.getIntegerForKey("height"); 
  42.     } 
  43.     void stepBackToRootSubDict(); 

 

 

 

 

 

 

 

 

 

 

 

 

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI