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

 

 

 

posted on 2012-08-03 11:48  SeanLin  阅读(3185)  评论(0编辑  收藏  举报

导航