<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>frames</key> <dict> <key>BG1.png</key> <dict> <key>frame</key> <string>{{0,0},{960,640}}</string> <key>offset</key> <string>{0,0}</string> <key>rotated</key> <false/> <key>sourceColorRect</key> <string>{{0,640}}</string> <key>sourceSize</key> <string>{960,640}</string> </dict> </dict> <key>Metadata</key> <dict> <key>format</key> <integer>2</integer> <key>realTextureFileName</key> <string>BG1-hd.pvr.ccz</string> <key>size</key> <string>{960,640}</string> <key>smartupdate</key> <string>$TexturePacker:SmartUpdate:c93237e161b27cfcb49ad4bc3e681a45$</string> <key>textureFileName</key> <string>BG1-hd.pvr.ccz</string> </dict> </dict> </plist>
中<key>frame</key> <string>{{0,640}}</string> <key>offset</key>
的二维数组读取其实是用到的COCOS2D-x中的Rect 结构
<pre class="cpp" name="code">Rect rect; rect=<span style="color:#ff6666;">RectFromString</span>(farscene->valueForKey("frame")->getCString()); // Point point=PointFromString() log("point=%f,%f,%f",rect.origin.x,rect.origin.y,rect.size.width,rect.size.height);
可以用红色字体所描出的函数来获取该二维数组,其实本身该plist文件中的{0,0},{960,640}代表的就是位置和大小,所以用 RectFromString()再合适不过了
该类型相同的函有三个,<span style="color:#3333ff;">PointFromString(),RectFromString(),SizeFromString();这是我今天的收获。</span>原文链接:https://www.f2er.com/cocos2dx/344793.html