TexturePacker批量合圖腳本

#!/bin/bash
CUR_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $CUR_PATH #當前文件夾路徑

# 填寫自己的路徑
TP="/Applications/TexturePacker.app/Contents/MacOS/TexturePacker"

#文件輸出路徑
OUTPUT_PATH="$CUR_PATH/out"


# --premultiply-alpha \ #這個參數可以消除白邊,但對白色透明變黑
# --dither-atkinson-alpha \

# --content-protection 5abc11740879b2ff6d36f2c9d4d7d088 \ #這個參數是圖片加密
function PackTextures(){
	if [ -f "${TP}" ]; then
		echo "building Images... ${1}"

		${TP} --smart-update \
		--texture-format png \
		--format cocos2d-x \
		--enable-rotation \
		--padding 2 \
		--shape-padding 2 \
		--trim-mode None \
		--scale 1.0 \
		--max-width 4096 \
		--max-height 4096 \
		--data  "$OUTPUT_PATH"/"${1}".plist \
		--sheet "$OUTPUT_PATH"/"${1}".png \
		--size-constraints AnySize \
		--opt RGBA8888 \
		--dither-atkinson-alpha \
		--reduce-border-artifacts \
		--inner-padding 1 \
		"${1}"/*.png
		echo "---------${1}\n\n"
	else
	    #if here the TexturePacker command line file could not be found
	    echo "TexturePacker tool not installed in ${TP}"
	    echo "skipping requested operation."
	    exit 1
	fi
}

#對當前目錄下的子文件下的png文件進行合圖操作
for dir in `ls` ;do
	if [ -d $dir ];then
		num="$(ls -l ${dir} | grep '.png' | wc -l)"
		if (($num > 0));then
			PackTextures $dir
		fi
	fi
done

--reduce-border-artifacts 應用於sprite內部,只改變全透明像素的顏色。主要解決縮放造成的白邊/黑邊。
--inner-padding 這個會讓圖片外面多一圈透明像素

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章