Ad
1: 2018-05-06 (日) 19:20:12 njf ソース バックアップ No.1 を復元して編集 現: 2018-05-06 (日) 20:39:06 njf ソース 編集
Line 23: Line 23:
  <string>{126,111}</string>   <string>{126,111}</string>
  </dict>   </dict>
 +
 +この中のdict二階層下の「<key>MLRSPanel0000</key>」とかの部分がフレーム名で、dict三階層目の「<string>{{4,4},{126,111~}}</string>」とかが、スプライトシート上のその画像の左上の座標と幅、高さをピクセルで表したものです。
 +
 +まず、この部分を取り出すPythonのスクリプトを書きました。
 +
 + from bs4 import BeautifulSoup
 + import sys
 + import os
 + import re
 + 
 + argvs = sys.argv
 + 
 + 
 + if len(argvs) < 2 :
 +     print "no file name"
 +     quit()
 + 
 + fileName = argvs[1]
 + 
 + if not os.path.exists(fileName):
 +     print "file does not exist"
 +     quit()
 + 
 + p = re.compile(u"[{|}|]")
 + p2 = re.compile(u",+")
 + 
 + with open(fileName, 'r') as f:
 +     bf = BeautifulSoup(f.read(),"html.parser")
 +     dictAll = bf.dict.dict
 +     frameName = ""
 +     for d in dictAll:
 +         if d.name == "key":
 +             frameName = d.get_text()
 +         elif d.name == "dict":
 +             for dd in d:
 +                 if dd.name == "string":
 +                     print frameName, p2.sub(u" ",p.sub(u"",dd.get_text()))
 +                     break
 +
 +このスクリプトの名前を「readSpCocos2ToCut.py」とすると、plistファイルを引数として
 +
 + python readSpCocos2ToCut.py texture.plist > texture.list
 +
 +を実行すれば、「texture.list」というファイルの中に、フレーム名、左上x座標、左上y座標、幅、高さのみを一覧にした以下のようなデータが書き込まれます。
 +
 + MLRSPanel0000 4 4 126 111
 + UpgradeIcon0000 134 4 28 18
 + artilleryPanel0000 166 4 118 68
 +
 +次に、ImagiMagickのconvertコマンドを使った以下のシェルを書き、「cropTexture.sh 」という名前で保存します
 + cat $1 | while read FN TL TT W H
 + do
 +  convert $2 -crop "$W"x"$H"+$TL+$TT  $FN.png
 + done
 +
 +そして先ほどのリストのファイルとtextureのpngファイルと実行すると、フレーム名のついたpngファイルが製作されます。
 +
 + sh cropTexture.sh texture.list texture.png


トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード印刷に適した表示   ページ新規作成 全ページ一覧 単語検索 最新ページの一覧   ヘルプ   最新ページのRSS 1.0 最新ページのRSS 2.0 最新ページのRSS Atom Powered by xpWiki
Counter: 1658, today: 1, yesterday: 0
MenuBar
広告

ログイン

ユーザー名:


パスワード:





パスワード紛失

Portuguese | English | German | Greek | Japanese | Korean | Russian | T-Chinese top
NJF