Cocos2d-html5資源預加載列表自動掃描腳本


Cocos2d-html5引擎資源加載列表的自動產生腳本,已經在捕魚達人上驗證過。

 腳本的使用方法:

1. 將腳本放到res目錄下(默認目錄名是res,當然你也可以手動替換為其他名字,修改path)

2. 修改輸出文件路徑和和資源文件夾的目錄名

3. 執行腳本,就能自動掃描當前目錄和子目錄的所有文件,自動判斷類型,產生出Cocos2d-html5支持的資源列表到js文件中。


# 1. Change the output file path by yourself 

outputfile=/Users/linshun/work/FishingJoyH5/FishingJoyResource.js


# 2. Specify your resources directory name

path="res"

 

loopDir(){


for file in find *

do 

if [ -d $file ] 

then 

echo "$file is directory" 

cd ./$file

loopDir

cd ..


elif [ -f $file ]

then

echo "$file is file"

if [ ${file##*.} = "png" -o ${file##*.} = "jpg" ] 

then

#echo "$extension"

echo "{type:\"image\", src:\"$path${PWD##*$path}/$file\"}," >>  $outputfile


elif [ ${file##*.} = "plist" ]

then

echo "{type:\"plist\", src:\"$path${PWD##*$path}/$file\"}," >>  $outputfile


elif [ ${file##*.} = "fnt" ]

then

echo "{type:\"fnt\", src:\"$path${PWD##*$path}/$file\"}," >>  $outputfile


elif [ ${file##*.} = "tga" ]

then

echo "{type:\"tga\", src:\"$path${PWD##*$path}/$file\"}," >>  $outputfile


elif [ ${file##*.} = "tmx" ]

then

echo "{type:\"tmx\", src:"$path${PWD##*$path}"/"$file"}," >>  $outputfile


elif [ ${file##*.} = "mp3" -o ${file##*.} = "ogg" ] 

then

#echo "$extension"

echo "{type:\"effect\", src:"$path${PWD##*$path}"/"$file"}," >>  $outputfile

fi

fi

done

}


# Release the resource array to js file.

echo "var g_ressources = [" >> $outputfile

loopDir 

#echo "{type:\"null\", src:\"null\"}" >>  $outputfile

# remove the last comma


echo "];" >> $outputfile


echo "Finish."

 

 

轉載請注明:SeanLin,http://www.cnblogs.com/SeanLin/archive/2012/08/03/2621325.html

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM