首页 技术 正文
技术 2022年11月12日
0 收藏 928 点赞 4,326 浏览 1848 个字

在d:\DevTool\cocos2d-x-2.2.2\cocos2d-x-2.2.2\tools\cocos2d-console\console

cocos2d_jscompile.py

cocos2d_version.py

cocos2d.py

cocos2d_new.py

d:\DevTool\cocos2d-x-2.2.\cocos2d-x-2.2.\tools\cocos2d-console\console>python
cocos2d.py jscompile --help
Usage: cocos2d.py jscompile -s src_dir -d dst_dir [-c -o COMPRESSED_FILENAME -j
COMPILER_CONFIG]Options:
-h, --help show this help message and exit
-s SRC_DIR_ARR, --src=SRC_DIR_ARR
source directory of js files needed to be compiled,
supports mutiple source directory
-d DST_DIR, --dst=DST_DIR
destination directory of js bytecode files to be
stored
-c, --use_closure_compiler
Whether to use closure compiler to compress all js
files into just a big file
-o COMPRESSED_FILENAME, --output_compressed_filename=COMPRESSED_FILENAME
Only available when '-c' option was True
-j COMPILER_CONFIG, --compiler_config=COMPILER_CONFIG
The configuration for closure compiler by using JSON,
please refer to compiler_config_sample.json

下面说一下可选参数,可选参数的意思是使用closure compiler工具压缩代码为一个文件。

COMPRESSED_FILENAME是压缩后的文件名,最好使用xxx.js,因为工具会自动再后面加个c

COMPILER_CONFIG是压缩时调用的配置文件,需要根据项目需求自己填写,在bin目录下有一个做好的缺省例子可以使用,compiler_config_sample.json

android

由于android下先要执行pro.android/build_native.sh脚本,所以我们可以在脚本里加入自动编译的功能,代码如下:

COCOS2D_CONSOLE=$COCOS2DX_ROOT/tools/cocos2d-console/console/
python $COCOS2D_CONSOLE/cocos2d.py jscompile -s assets/script/ -d assets/src/;
cd assets/src;
find .-type f -name "*.js"| xargs rm -rf;
cd ../../;

以上代码要放在调用NDK编译之前。

ios

由于ios下编译没有对应的build_native.sh脚本,所以就没法使用类似的方式了。幸好xcode下编译时可以添加自定义的run script

选择 项目 -> TARGETS -> Build Phases -> Add Build Phases -> Add Run Script,添加如下的内容:

source ~/.bash_profile
CONSOLE_PATH=$COCOS2DX_ROOT"/tools/cocos2d-console/console/";
TARGET_DIR=$BUILT_PRODUCTS_DIR"/"$PRODUCT_NAME".app/";
JS_DIR=$TARGET_DIR"/src/";/usr/bin/python $CONSOLE_PATH/cocos2d.py jscompile -s $JS_DIR -d $JS_DIR;
find $JS_DIR -type f -name "*.js"| xargs rm -rf;

这样在编译时就会自动调用该脚本。(需要在.bash_profile里定义cocos2dx的根目录,并且变量名为COCOS2DX_ROOT)

将js编译为字节码发布,就不用担心别人可以拿到js源代码了。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,031
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,520
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,368
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,148
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,781
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,859