如何在编译cocos2d项目加入自己的脚本
来源:互联网 发布:淘宝是什么 编辑:程序博客网 时间:2024/05/15 20:23
COCOS2D-CONSOLE
- Cocos2d-console
- Overview
- Requirement
- Setup Environment
- Usage
- Attentions
- How to add command
- Add custom steps during compiling
- Advanced Features
- Contributing
Overview
cocos2d-console is a command line tool for cocos2d-x & cocos2d-js. It contains several commands for developers to create, compile, run
the -x
or -js
projects.
The cocos2d-console is implemented by Python
. You can use it in Windows, Mac or Linux
.
Requirement
- Python 2.7 is required (Now only support version 2.7).
- Required by iOS & Mac:
- XCode
- Required by android:
- Android NDK
- Android SDK
- Apache Ant
- Required by win32:
- Visual Studio
- Required by linux:
- Please run the
build/install-deps-linux.sh
incocos2d-x
orcocos2d-js
to install the dependencies.
- Please run the
Setup Environment
Run the setup.py
in the root directory of cocos2d-x
or cocos2d-js
.
If you are developing games for android, you should input the Android SDK
, Android NDK
& Apache Ant
path when the setup is running.
Usage
Use the command line like this:cocos [command] [arguments]
Available commands:
- new
- compile
- deploy
- run
- jscompile
- luacompile
- gen-libs
- gen-simulator
- gen-templates
- package
Attentions
There are depend relationship between commands. Two rules about dependencies:
- The dependent commands will be invoked first.
- If command A depend on command B. When you are using command A, the arguments you used will be passed to command B.
For example: Command run
depends on command deploy
, and deploy
depends on compile
.
- The command order is
compile->deploy->run
. - You can use command
run
like this:cocos run -p android --ndk-mode release
(-p
is available argument ofrun
,--ndk-mode
is available argument ofcompile
)
How to add command
Edit
bin/cocos2d.ini
, and add the class name of your new plugin there. For example:Create a file called
plugin_custom.py
in theplugins
folder.
A new, empty plugin, would look like the code shown below:Check the added command. The output of
cocos -h
will show the available commands:
The result of run the commandcocos custom -p android
will look like this:
Add custom steps during compiling
When cocos compile
is running, some events will be dispatched to the custom python scripts. You can use this function by these steps:
Define your custom script in
.cocos-project.json
in the root of your project. like this:The key must be
custom_step_script
. The value can be absolute or relative path.Define a method named
handle_event
in your custom script like this:
Then your custom script will be invoked when you are compiling your project by cocos compile
.
Here are the pre-defined events:
assets-dir
: The path of assets directorypost-copy-assetsandroidassets-dir
: The path of assets directorypre-ant-buildandroid---post-ant-buildandroid---All events arguments will contains:
- project-path : The path of project root directory.
- platform-project-path : The path of current compiling platform directory.
- build-mode : The value of parameter
-m
. It'srelease
ordebug
- output-dir : The path of output directory.
- ndk-build-mode : The value of parameter
--ndk-mode
. It'srelease
ordebug
ornone
. (This argument is only available when target platform is android).
Advanced Features
- How to exclude files in resources directory when building for android
Contributing
The code repository of cocos2d-console
is on github: console repository
You can fork this github repository, add your contribution, then send a pull request to us.
- 如何在编译cocos2d项目加入自己的脚本
- cocos2d-x如何继承CCMenu并且在触摸函数中加入自己的实现
- [cocos2d-x 学习] 如何编译自己的项目(从win32交叉编译到android)
- 在自己的程序中加入脚本支持(一)
- 在自己的程序中加入脚本支持(二)
- 如何把GRETA加入到自己的项目中
- 如何把GRETA加入到自己的项目中
- 在Cocos2d-x项目中,如何将自己的类添加到Classes文件夹下
- 在Cocos2d-x项目中,如何将自己的类添加到Classes文件夹下
- 在自己的SSH项目中加入WebService
- 在自己的SSH项目中加入WebService
- 如何在自己的程序中加入宏的功能
- 如何在你的软件中加入脚本功能
- 如何在patform中加入自己的工程
- 【转】如何在weka中加入自己的算法
- 如何在自己的网站加入qq在线交谈功能
- 如何在自己的Android APP中加入广告
- Cocos2d-x3.0自己写的项目编译笔记
- Dll注入技术之注册表注入
- 2014 年最热门的国人开发开源软件 TOP 100
- Quartz任务调度快速入门
- 通过 iwpriv 指令修改工厂参数
- Storm使用到的相关技术总结
- 如何在编译cocos2d项目加入自己的脚本
- selenium多个窗口操作及切换
- git,npm,bower等设置代理
- 调色板的简单实现
- 你应该知道的那些Android小经验
- Activity生命周期
- 硬中断与软中断的区别
- Android AsyncTask和Handler对比
- Inno Setup安装、卸载时判断是否程序正在运行