以下是在Windows平台上的操作过程,如果是其他平台,可以参考自带文档READ.md内的操作说明,本篇文章也是参考READ.md
cocos2d-x 3.0之后创建新工程使用的是cocos.bat这个脚本,位置在.....\cocos2d-x-3.8.1\tools\cocos2d-console\bin 内,
需要安装Python27并把python的安装目录加到PATH环境变量内。
假设我们要创建一个名字叫MyGame的游戏,游戏位置放到cocos2d-x-3.8.1\tests\ 内,则操作步骤如下:
Example:
> cd cocos2d-x
> setup.py
> cocos new MyGame -p com.your_company.mygame -l cpp -d .\tests
注意:setup.py这个脚本是安装环境变量的,在执行过程中,会让你指定ANDROID的一些路径,可以直接回车跳过,以后需要时再重新指定,
还有个问题就是Windows的终端很搓,在设置完环境变量后,要重启终端,所以第二部执行完后记得重启一下cmd,否则会提示找不到cocos云云……
如果一切正常,这样之后工程就创建完成了。
去 .\tests\MyGame\proj.win32目录,打开MyGame.sln,OK,收工。
附1: 脚本setup.py的说明
This script will install environment variables needed to by cocos2d-x. It will set these envrironment variables:
* COCOS_CONSOLE_ROOT: used to run cocos console tools,more information about cocos console tools please refer to
https://github.com/cocos2d/cocos2d-console
* NDK_ROOT: used to build android native codes
* ANDROID_SDK_ROOT: used to generate applicatoin on Android through commands
* ANT_ROOT: used to generate applicatoin on Android through commands
* COCOS_X_ROOT: path where cocos2d-x is installed
* COCOS_TEMPLATES_ROOT: path where cocos2d-x's templates are installed
附2:READ.md内关于创建工程的一些说明文档
How to start a new game ----------------------- 1. Download the code from [cocos2d download site][4] 2. Run `setup.py` 3. Run the `cocos` script Example: $ cd cocos2d-x $ ./setup.py $ source FILE_TO_SAVE_SYSTEM_VARIABLE $ cocos new MyGame -p com.your_company.mygame -l cpp -d NEW_PROJECTS_DIR $ cd NEW_PROJECTS_DIR/MyGame You can also create a JS project or Lua project with `-l js` or `-l lua`. ### Build and run a new project for Android ### $ cocos run -p android -j 4 ### Build and run a new project for iOS ### $ cocos run -p ios ### Build and run a new project for OSX ### $ cocos run -p mac ### Build and run a new project for Linux ###