Coocs2d: Use Cocos2d

Source: Internet
Author: User
1. Each version of the directory changes. This version is no exception. A configuration file named setup. py is added to the root directory of the file. You can run it to configure some environment variables of the system. 2. Create a new project version. Find the package named cr in the tools Folder...

1. Each version of the directory changes. This version is no exception. A configuration file named setup. py is added to the root directory of the file. You can run it to configure some environment variables of the system. 2. Create a new project version. Find the package named cr in the tools Folder...

1. Directory change

Each version has a Directory change, and this version is no exception. A configuration file named setup. py is added to the root directory of the file. You can run it to configure some environment variables of the system.

2. Create a project

For a new version, create a new project. Find the file named create-project.py packaged in the tools Folder... it seems that the wood is ready! It turns out that in the new version, you can create a new project through the command line. Compared with the graphic interface of the previous version, the command line is simpler. We need to set parameters in setup. py. Take the mac platform as an example. We enter the corresponding directory and 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 cocos2dx command line path, android_sdk path, and ant_root path. These paths are required for Android package. Next we will run:

source ~/.bash_profile

In this way, you can configure the variable to bash_profile. Next, we can create a project. Here we use a cocos new command, which is a bit humorous for c ++ programmers who allocate a piece of memory and a touch.

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'

In this way, our project has been created.

3. Package and run

Go to the project directory and run the "cocos run" command line 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

The command uses "-p" to set the platform. If it is set to ios, the simulator is automatically opened after a piece of compiled information.

......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: 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

Then we are familiar with the log.



Next, we will test Android packaging. Run "cocos run ". The debug apk is displayed 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 -

Now we can start the android simulator or connect to the real machine to install and run our apk.

4. Minor problems

When I run the Android simulator on a black screen, view the logcat display:

E/libEGL  (  331): called unimplemented OpenGL ES API

Visual testing is a problem of openGL calling. I connected the real machine again and found that it could run. Is it possible that it is a problem with the simulator configuration? I hope I can leave a message about my children's shoes.

In addition, running setup. py on the win32 platform reports an error.: This problem is caused by the python version. You can fix it by changing the python version from 3.3 to 2.7.

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

After reading the code, it seems that a problem occurred while obtaining 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-bit. If 360 is disabled, the operation of the Administrator permission is invalid. Maybe my registry is weird? I also want to know how to solve this problem ~


This blog is from ashboard http://blog.csdn.net/fansongy/article/details/21297445.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.