重命名相关资源文件:
将xxx.png图片改名为xxx.png.XXX 【XXX自定义】 将xxx.ogg声音改名为xxx.ogg.XXX
资源load时 需要 资源名字 + XXX
public static Image createImage(String filePathName){
filePathName += XXX;
.
.
.
}
参数filePathName,将接受从游戏传过来的资源路径参数。比如 Image.createImage("file://pic/xxx.png");
其实更好的方式是把资源都做成工具特有的格式,可以起到游戏资源的加密作用。
2011.9.16
问题:声音文件改了后缀之后MediaPlayer加载资源的时候
AssetFileDescriptor afd = AppConfig.getAssetManager().openFd(pathName);
global_music[resID].setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
抛出异常:java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed原因:Asset目录下非特定后缀名得文件都会被压缩,而openFd只能打开未压缩的文件。
from Dealing with Asset Compression in Android Apps(避免asset目录下文件被压缩)
不压缩的格式:
/* these formats are already compressed, or don't compress well */ static const char* kNoCompressExt[] = { ".jpg", ".jpeg", ".png", ".gif", ".wav", ".mp2", ".mp3", ".ogg", ".aac", ".mpg", ".mpeg", ".mid", ".midi", ".smf", ".jet", ".rtttl", ".imy", ".xmf", ".mp4", ".m4a", ".m4v", ".3gp", ".3gpp", ".3g2", ".3gpp2", ".amr", ".awb", ".wma", ".wmv" };
解决方案:
I 使用上面这些格式,但是隐藏效果没有了。
II asset文件处理的时候不压缩特定格式【我们自定义的XXX】的文件。
III 先把文件拷贝到SD卡里 能后通过setDataSource(GameConfig.GAME_PATH_SD+"/"+pathName)来设置资源