您好,登錄后才能下訂單哦!
先要做準備工作
先下載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作對照
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
- <plist version="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>
下面提供一個解析的函數
- void collision::plistParse()
- {
- //Load rootDict from file, and then step into the metadata sub dict.
- DS_Dictionary rootDict;
- if(!rootDict.loadRootSubDictFromFile(bgObjectPlist))
- {
- printf("no load\n");
- }
- if(!rootDict.stepIntoSubDictWithKey("texture"))
- {
- printf("No texture\n");
- }
- //Get an int value from the subdict
- int someInt = rootDict.getIntegerForKey("height");
- printf("height %d\n",someInt);
- someInt = rootDict.getIntegerForKey("width");
- printf("width %d\n",someInt);
- //Step out of the sub dict and into another
- rootDict.stepOutOfSubDict();
- if(!rootDict.stepIntoSubDictWithKey("frames"))
- {
- printf("no dic\n");
- }
- for(int i=0;i<3;)
- {
- char picture[20];
- sprintf(picture,"bg_%d.png",i);
- if(!rootDict.stepIntoSubDictWithKey(picture))
- {
- i++;
- //printf("No %s\n",picture);
- rootDict.stepOutOfSubDict();
- continue;
- }
- int x=rootDict.getIntegerForKey("x");
- int y=rootDict.getIntegerForKey("y");
- int width=rootDict.getIntegerForKey("width");
- int height=rootDict.getIntegerForKey("height");
- }
- void stepBackToRootSubDict();
- }
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。