cocos2d-x创建项目的方式又改了
1、创建项目
新的版本我们来动手创建一个新项目吧。找到tools文件夹....额 打包的那个名为create-project.py的文件似乎木有了!原来,在新版本中,创建新项目已经可以通过命令行来创建了,相对于先前版本的图形界面,命令行更简洁。我们要在setup.py中设置参数。以mac平台为例,我们进入到对应目录,运行脚本setup.py:
Setting up cocos2d-x... -> Adding COCOS2D_CONSOLE_ROOT environment variable... OK -> Added: COCOS_CONSOLE_ROOT = /Users/fansy/Documents/cocos2d-x-3.0rc0/tools/cocos2d-console/bin -> Looking for NDK_ROOT envrironment variable... FOUND -> Looking for ANDROID_SDK_ROOT envrironment variable... NOT FOUND Please enter its path (or press Enter to skip): /Users/fansy/lib/android-sdk-macosx ADDED -> Added: ANDROID_SDK_ROOT = /Users/fansy/lib/android-sdk-macosx -> Looking for ANT_ROOT envrironment variable... NOT FOUND Please enter its path (or press Enter to skip): /Users/fansy/Documents/ant-1.9.3/bin ADDED -> Added: ANT_ROOT = /Users/fansy/Documents/ant-1.9.3/bin Set up successfull: ANT_ROOT was added into /Users/fansy/.bash_profile Please execute command: "source /Users/fansy/.bash_profile" to make added system variables take effect
显然,我们在这里设置了cocos2dx命令行的路径,android_sdk的路径,ant_root的路径。这些路径都是打Android包需要使用的。接下来我们运行:
source ~/.bash_profile
这样就可以将变量配置到bash_profile中。接下来我们就可以创建项目了,这里使用了一个cocos new命令
localhost:~ fansy$ cocos new Runing command: new usage: cocos new [-h] [-p PACKAGE_NAME] -l {cpp,lua,js} [-d DIRECTORY] [-t TEMPLATE_NAME] [--no-native] [PROJECT_NAME] cocos new: error: argument -l/--language is required localhost:~ fansy$ cocos new HelloNew2dx -p com.fansy.hello -l cpp -d ~/Documents/Code/ Runing command: new > Copy template into /Users/fansy/Documents/Code/HelloNew2dx > Copying cocos2d-x files... > Rename project name from 'HelloCpp' to 'HelloNew2dx' > Replace the project name from 'HelloCpp' to 'HelloNew2dx' > Replace the project package name from 'org.cocos2dx.hellocpp' to 'com.fansy.hello'
3、打包运行
进入项目目录,我们可以直接运行"cocos run"命令行,在各平台上运行。
localhost:~ fansy$ cd ~/Documents/Code/HelloNew2dx/ localhost:HelloNew2dx fansy$ cocos run Runing command: compile The target platform is not specified. You can specify a target platform with "-p" or "--platform". Available platforms : win32, android, ios, mac, linux localhost:HelloNew2dx fansy$ cocos run -p ios
命令通过“-p”来设置平台,设置成ios的话,在一段编译的信息后,会自动打开模拟器。
......blablabla...... ** BUILD SUCCEEDED ** build succeeded. Runing command: deploy Deploying mode: debug Runing command: run starting application running: '/Users/fansy/Documents/cocos2d-x-3.0rc0/tools/cocos2d-console/bin/../plugins/project_run/bin/ios-sim launch /Users/fansy/Documents/Code/HelloNew2dx/bin/debug/ios/HelloNew2dx.app &' localhost:HelloNew2dx fansy$ 2014-03-15 19:08:35.432 HelloNew2dx iOS[1522:80b] cocos2d: surface size: 960x640 cocos2d: { cocos2d.x.version: 3.0-rc0 cocos2d.x.compiled_with_gl_state_cache: true cocos2d.x.build_type: DEBUG gl.supports_vertex_array_object: true cocos2d.x.compiled_with_profiler: false gl.renderer: Apple Software Renderer gl.vendor: Apple Computer, Inc. gl.max_texture_size: 4096 gl.max_samples_allowed: 4 gl.version: OpenGL ES 2.0 APPLE-9.2.1 gl.supports_S3TC: false gl.supports_ATITC: false gl.supports_ETC1: false gl.max_texture_units: 8 gl.supports_PVRTC: true gl.supports_NPOT: true gl.supports_discard_framebuffer: true gl.supports_BGRA8888: false } libpng warning: iCCP: known incorrect sRGB profile
接下来测试Android打包。同样运行“cocos run”。会打出debug的apk,并自动连接到设备上。
localhost:HelloNew2dx fansy$ cocos run -p android -j 4 Runing command: compile Building mode: debug building native The Selected NDK toolchain version was 4.7 ! ......blablabla.......... BUILD SUCCESSFUL Total time: 4 seconds Move apk to /Users/fansy/Documents/Code/HelloNew2dx/bin/debug/android build succeeded. Runing command: deploy Deploying mode: debug installing on device running: '/Users/fansy/lib/android-sdk-macosx/platform-tools/adb uninstall com.fansy.hello' - waiting for device -
这时我们打开android模拟器,或连接真机,即可安装运行我们的apk了