From cocos2d-x-2.x to cocos2d-x-3.x: Lua project configuration

Source: Internet
Author: User

The official version of the cocos2dx-x3.0 came out for a while, and now the latest version is up to 3.2 Alpha, and 2. in addition to the Wiki on the official website, the relevant information that can be found in the X series is not much different. the differences and problems of X are recorded here.

And 2. X shell script, 3. all the configurations of the X series are made in Python. The biggest benefit is, of course, cross-platform. In Windows, you can also compile the Android version from cywin. Although the IOS version is still inseparable from xcode, however, it is good to compile different versions for Mac and win respectively, saving time and effort.

Start with python. in addition to compiling the Android version, the Lua project of X also has the generation of LUA-binding, and 2. X must be written in tolua ++. PKG files are different. the bindings-generator used by X (located in the cocos2d-x/tools) is basically fully automated resolution, some of the new CPP classes you need to bind yourself only need to add (Parts independent of the cocos2d-x module) or modify (modify the cocos2d-x itself) A Bit Of The cocos2d-x/tools/Under the INI file, it is indeed quite convenient, but it is difficult to configure it.

You want to run genbindings under the cocos2d-x/tools/tolua. PY to generate the corresponding binding file (located in cocos2d-x \ Cocos \ Scripting \ LUA-bindings \ auto, you can also modify genbindings. to generate a file in different paths), you must first prepare two plug-ins, namely Python and python, and ndk. Python can also be used to generate the 3.x project file and compile the Android version. The project is generated later. Although there are some causal inversion, we should start from here in advance.

Readme under cocos2d-x \ tools \ tolua. how to install mdown and Wiki on the official website. Here we will talk about the configuration of Windows separately. There are many manual DIY parts for Windows:

1. readme said the need is ndk: android-ndk-r9b, the latest version of the official website is android-ndk-r9d, it is recommended to use the latest version, according to the operating system to select a 32-bit or 64-bit version, it must be consistent with the following ADT and JDK, but if r9c and r9d are used, you need to change 4.7 in android_headers in ini under tolua to 4.8, this is the reason why r9b is required in readme. (If r9c is used to generate an error, you must modify the corresponding math in the ndk according to the error message. h file to comment out the line with the error), decompress it, and add the decompressed path to the ndk_root environment variable.

2. Install python, (32bit) from (http://www.python.org/ftp/python/2.7.3/python-2.7.3.msi). This is strictly in accordance with the requirements, note that the 32-bit version, 64-bit version can not install the required two plug-ins. After installation, add the python installation path to the environment variable path, and re-run the CMD command line and enter python to check whether it can be verified. Then install pyyaml: http://pyyaml.org/download/pyyaml/PyYAML-3.10.win32-py2.7.exe and pycheetah: https://raw.github.com/dumganhar/cocos2d-x/download/downloads/Cheetah.zip, and decompress it to the python path "python27 \ Lib \ Site-packages ".

In this way, everything is ready. Run Python genbindings. py in the tolua path of CMD, and then you can generate Lua binding.

After that, return to the start of the project configuration, the role of Python has been installed, ndk also checked in, to through the cocos2d-x below the setup. some other things are required to generate a new project in Py, which is basically used to compile the android project:

ADT: Android development tools. Pay attention to the 32-bit or 64-bit version, which is consistent with ndk and JDK. This determines the android API level, you can use the accompanying skdmanager to download the android APIs of different versions for compilation. Download the package, decompress it, and add android_sdk_root in the environment variable to point to the SDK directory in this path. In the future, you can use eclipse to debug the android project generated.

JDK: Java SE Development Kit. We still pay attention to the 32-bit or 64-bit version, which is consistent with ndk and ADT. It must be JDK and only JRE does not work. After the installation is completed, add java_home in the environment variable to point to this path. You can enter Java and javac in cmd to verify the installation.

Ant: Apache ant, used to help compile the android Project (APACHE ant is a Java library and command-line tool that help building software). After downloading it, pressurize it, add ant_root to the bin directory under this path in the environment variable, and then add it to the path. You can enter ant verification in cmd.

Finally, add an environment variable cocos_console_root pointing to the path "cocos2d-x-3.x \ tools \ cocos2d-console \ bin", and then you can run Python setup. py in cmd to the path of the cocos2d-x-3.x. In this way, everything is done (?), Run Cocos in cmd to create a project, compile a project, and other one-stop services. Create a new project: Cocos new mygame-p com. mycompany. mygame-l LUA-D. /mycompany,-P is followed by the android package name.-l can select CPP or Lua, and-D is the directory, this actually generates a new project configuration file based on different project templates (under cocos3.x/tests.

After the command is generated, run cmd to enter the directory. You can enter Cocos compile-h to check the compiled parameter table. Many options are added for 3.2alpha. -P android can generate an android project. The parameter following the AP is the android API level in the ADT, and a useful one is ndk-mode, in addition to debug and release, you can also select clean as the parameter to recompile the project.

Cocos the python files used by this command are under the cocos2d-x-3.x \ tools \ cocos2d-console, compile Android project_compile/build_android.py under the plugin directory, if you want to add other paths to be compiled (such as the CPP library you want to use), you can modify this file and add a new path to ndk_module_path.

 

Compared to the cocos2d-x-2.x that Windows system needs to run build_native.sh in cywin to compile the android project, the new Python-based configuration file should be more automated and scripted, although at the very beginning, I felt that the Cocos command was integrated with many functions, which made people not know where to start. x, a file comes directly (3. X can also be a file, that is, build_android.py, which can be configured with a little bit and then Python build_android.py-P apilevel mygame). However, after a period of time, regardless of the Lua binding or automatic compilation process, 3. X this script configuration has to evolve a lot. Of course, 3. X is relative to 2. X evolved not only in this respect, but also many new feature (pitfall). Let's take a look at the next decomposition.

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.