1、下載TexturePacker
推薦使用TexturePacker,使用免費功能建立咱們的須要的已經足夠了,收費功能暫時不須要,下載地址:http://www.codeandweb.com/texturepacker/html

下載安裝便可。web
2、無償使用

使用第三個選項:」Use free「便可,咱們用不到收費功能app
3、放入小圖

將該小圖拖入到右邊的Sprites窗口裏就能夠了,再依次拖入其它圖片spa

依次拖入圖片後,軟件會自動選擇空位置將圖片安排進去,同時記錄圖片在圖中的位置,細心的讀者可能發現有一張圖片旋轉了,這都是軟件爲了節省空間自動旋轉的,咱們不須要管它,同時在代碼中引用時也不須要管,plist文件會記錄,咱們仍是隻須要引用圖片名稱就好了。最後將圖片導出。.net
4、導出圖片和plist文件
點擊Publish,選擇文件導出位置就能夠了3d

最後,圖片和對應的plist文件就生成好了,咱們能夠用於Cocos2d開發遊戲了……code
我製做的:orm

對於plist文件是如何保存圖片位置的?xml
plist文件數一個xml文件咱們能夠用Eclipse或者記事本打開htm
[html] view plain copy
- <?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>character1.png</key>
- <dict>
- <key>frame</key>
- <string>{{2,2},{68,90}}</string>
- <key>offset</key>
- <string>{1,-5}</string>
- <key>rotated</key>
- <false/>
- <key>sourceColorRect</key>
- <string>{{15,10},{68,90}}</string>
- <key>sourceSize</key>
- <string>{96,100}</string>
- </dict>
- <key>character2.png</key>
- <dict>
- <key>frame</key>
- <string>{{72,2},{76,88}}</string>
- <key>offset</key>
- <string>{2,-6}</string>
- <key>rotated</key>
- <false/>
- <key>sourceColorRect</key>
- <string>{{17,12},{76,88}}</string>
- <key>sourceSize</key>
- <string>{106,100}</string>
- </dict>
- <key>character3.png</key>
- <dict>
- <key>frame</key>
- <string>{{150,2},{76,100}}</string>
- <key>offset</key>
- <string>{8,4}</string>
- <key>rotated</key>
- <true/>
- <key>sourceColorRect</key>
- <string>{{23,1},{76,100}}</string>
- <key>sourceSize</key>
- <string>{106,110}</string>
- </dict>
- </dict>
- <key>metadata</key>
- <dict>
- <key>format</key>
- <integer>2</integer>
- <key>realTextureFileName</key>
- <string>picture.png</string>
- <key>size</key>
- <string>{252,94}</string>
- <key>smartupdate</key>
- <string>$TexturePacker:SmartUpdate:4d9f9052f72b479531d5262ac554d5db:c14790402c7beb896b15e46c664da0c0:aee6d656c46f4f58abed154134950510$</string>
- <key>textureFileName</key>
- <string>picture.png</string>
- </dict>
- </dict>
- </plist>
不難看出,一個<key>對應一個值,這個值多是矩形區域<dict>,也多是字符串<string>,按照這個方法,這樣咱們拿第一張圖character1.png來解析
character1.png: 屬性 // 小圖的名稱,在代碼中能夠直接經過該名稱引用圖片
frame: {{2,2},{68,90}} // 圖片所在區域左上角和右下角的座標 offset: {2,-6} // 未知 rotated: false // 是否旋轉,能夠看到第三張的值爲true sourceColorRect: {{23,1},{76,100}} // 未知 sourceSize: {106,110} // 未知