No exception. Most prominently, a configuration file named setup.py is added to the root directory of the file. Run it to configure some of the system's environment variables.
2. Create a project
New version let's start by creating a new project. Find the Tools folder .... The size of the create-project.py file seems to have been wood! Originally, in the new version, the creation of a new project can already be created by the command line, the command line is more concise than the previous version of the graphical interface. We want to set the parameters in the setup.py. Take the Mac platform for example, we go to the corresponding directory, run the script 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 FOUNDPlease 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 FOUNDPlease enter its path (or press Enter to skip): /Users/fansy/Documents/ant-1.9.3/binADDED-> Added: ANT_ROOT = /Users/fansy/Documents/ant-1.9.3/binSet up successfull:ANT_ROOT was added into /Users/fansy/.bash_profilePlease execute command: "source /Users/fansy/.bash_profile" to make added system variables take effect
Obviously, here we set the path of the COCOS2DX command line, android_sdk path, ant_root path. These paths are all needed to play the Android package. Next we run:
source ~/.bash_profile
This allows the variable to be configured in Bash_profile. Then we can create the project, which uses a Cocos new command, a bit like the C + + allocation of a piece of memory, the programmer brother is very humorous.
localhost:~ fansy$ cocos newRuning command: newusage: 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 requiredlocalhost:~ 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‘
So our project is created.
3. Package Run
Into the project directory, we can run the "Cocos Run" command line directly, running on each platform.
localhost:~ fansy$ cd ~/Documents/Code/HelloNew2dx/localhost:HelloNew2dx fansy$ cocos run Runing command: compileThe target platform is not specified.You can specify a target platform with "-p" or "--platform".Available platforms : win32, android, ios, mac, linuxlocalhost:HelloNew2dx fansy$ cocos run -p ios
command to set the platform through "-P", set to iOS, after a compilation of information, will automatically open the simulator.
... blablabla......** BUILD succeeded **build succeeded. runing command:deploydeploying mode:debugruning command:runstarting applicationrunning: '/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: 960x640cocos2d: {cocos2d.x.version:3.0-rc0 cocos2d.x.compiled_with_gl_state_cache:true cocos2d.x.build_type:d Ebug gl.supports_vertex_array_object:true cocos2d.x.compiled_with_profiler:false gl.renderer:Apple software Re Nderer 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.suppor Ts_npot:true Gl.supports_diScard_framebuffer:true gl.supports_bgra8888:false}libpng warning:iCCP:known Incorrect SRGB profile
Then there is the log we are familiar with.
Next Test Android packaging. Also run "Cocos Run". The debug apk will be played and automatically connected to the device.
localhost:HelloNew2dx fansy$ cocos run -p android -j 4Runing command: compileBuilding mode: debugbuilding nativeThe Selected NDK toolchain version was 4.7 !......blablabla..........BUILD SUCCESSFULTotal time: 4 secondsMove apk to /Users/fansy/Documents/Code/HelloNew2dx/bin/debug/androidbuild succeeded.Runing command: deployDeploying mode: debuginstalling on devicerunning: ‘/Users/fansy/lib/android-sdk-macosx/platform-tools/adb uninstall com.fansy.hello‘- waiting for device -
When we open the Android emulator, or connect the real machine, we can install and run our apk.
4, the small problems encountered
I run the Android emulator when the black screen, view logcat display:
E/libEGL ( 331): called unimplemented OpenGL ES API
Visual inspection is an issue with OpenGL calls. I am connected to the real machine, found to be able to run, estimated that there may be a problem with the emulator configuration? Want to have to know the children's shoes message to tell me.
also run setup.py error on Win32 platform : This problem is caused by Python version, change Python version from 3.3 to 2.7 can fix
C:\OutFile\cocos2d-x-3.0rc0>python setup.py File "setup.py", line 114 print ‘Warning: Could not add "%s" into registry‘ % key ^SyntaxError: invalid syntax
I looked at the code, which seemed to be a problem when I took the registry.
def _set_environment_variable_win32(self, key, value): import _winreg try: env = None env = _winreg.OpenKeyEx(_winreg.HKEY_CURRENT_USER, ‘Environment‘, 0, _winreg.KEY_SET_VALUE | _winreg.KEY_READ) _winreg.SetValueEx(env, key, 0, _winreg.REG_SZ, value) _winreg.FlushKey(env) _winreg.CloseKey(env) except Exception: if env: _winreg.CloseKey(env) print ‘Warning: Could not add "%s" into registry‘ % key return False return True
My environment is Win7 64 bits. Has been turned off 360, administrator privileges run also invalid, do not know what is going on. Could it be that my registry is more bizarre? Also want to know how to solve this problem of children's shoes message ~