3. Cocos2dx 3.0 game development: finding a third-party game development environment

Source: Internet
Author: User

Respect the developer's labor results, reprinted, please note the Source: http://blog.csdn.net/haomengzhu/article/details/27107295


Build a Development Environment

One of the great conveniences of using Cocos2d-x is that we can complete coding and most debugging in a PC or Mac environment before migrating to other devices
To test the environment. This means that we can develop games on the PC and migrate the games to iOS or other platforms at extremely low costs.

Saves a lot of device fees during the development phase.


As mentioned above, Cocos2d-x can be deployed on multiple platforms and the specific steps are not complex


Now, follow the steps below to build a development environment on the PC.

1. Correctly install Visual Studio 2010 (hereinafter referred to as ).

2. download the latest Cocos2d-x source code from the official website and unzip it. Here we use cocos2d-x 3.0.

Download cocos2d-x 3.0 official
Http://www.cocos2d-x.org/download

3. Download android sdk and ndk

Http://developer.android.com/sdk/index.html

4. Download ant
Http://ant.apache.org

(Note: cocos2d-x environment variable configuration requires ant, mainly android needs to use it)

5. Download python 2.7.6 (do not download python or later)
Https://www.python.org/download/releases/2.7.6/
All the necessary tools have been downloaded. Now we have started to build the environment.

6. Now we can configure 3.0 environment variables, which is much more convenient.
Just run setup. py in the 3.0 directory.



Enter the relevant path as prompted;


7. When creating a project, I believe that 3.0 of the heroes who have used it all know that there is a cocos command.
Run cocos-h here to see help





After the establishment of the development environment, we will create the first Cocos2d-x project, named "findmistress" is to find small three:




8. Find the Created directory:

After creating a project, use VS2012 to open the win32 project, and then run the compilation;

In VS's Solution Explorer, you can see the file directory structure of a typical Cocos2d-x project, where the "Classes" folder stores game code, the "resource" folder stores game resources. Other projects are the source code that stores the Cocos2d-x engine and other dependent projects.

Typically, the Cocos2d-x project already contains the necessary external dependent libraries, so we only need to modify the game code and resources.


Directly run the project without any modification. The first compilation may take a long time. After compilation is complete, start debugging.

If the Cocos2d-x sign is shown, congratulations, your environment is set up successfully and your first Cocos2d-x game is running successfully:



This completes the entire environment.


9. Next I will talk about android.

First, go to the proj. android directory and run the command



After the compilation is complete, open it with eclipse, and import it to see the red "*".




This is because the package is missing. Right-click the attribute and you will see



To E: \ cocos2d-x-3.0 \ projects \ findmistress \ cocos2d \ cocos \ 2d \ platform \ android \ java \ src copy the class package to the src of the current project, you can also use a class library to reference a project.

There is no problem after refreshing:



But the problem arises. It is too much trouble to copy every creation.
Modify build_native.py in the template class
You can find build_native.py under "cocos2d-x-3.0/templates/cpp-template-default/proj. android" to modify it.
Next, modify the build_native.py file in the template, and then let the Command help us to test the class package together.

<span style="font-family:KaiTi_GB2312;">def copy_resources(app_android_root):    # remove app_android_root/assets if it exists    assets_dir = os.path.join(app_android_root, "assets")    if os.path.isdir(assets_dir):        shutil.rmtree(assets_dir)    # copy resources    os.mkdir(assets_dir)    resources_dir = os.path.join(app_android_root, "../Resources")    if os.path.isdir(resources_dir):        copy_files(resources_dir, assets_dir)#--------copy cocos_lib_path start------------def copy_src_files(src, dst):        for item in os.listdir(src):        path = os.path.join(src, item)                if not item.startswith('.') and os.path.isfile(path):            shutil.copy(path, dst)        if os.path.isdir(path):            new_dst = os.path.join(dst, item)            if not os.path.exists(new_dst):                os.mkdir(new_dst)            copy_src_files(path, new_dst)def copy_src(app_android_root,cocos_root):      android_src_dir = os.path.join(app_android_root,"src")        cocos_src_path = os.path.join(cocos_root, "cocos/2d/platform/android/java/src")        if not os.path.exists(android_src_dir) :        os.mkdir(android_src_dir)        if os.path.isdir(cocos_src_path):        copy_src_files(cocos_src_path,android_src_dir)#--------copy cocos_lib_path end------------def build(ndk_build_param,android_platform,build_mode):    ndk_root = check_environment_variables()    sdk_root = None    select_toolchain_version()    current_dir = os.path.dirname(os.path.realpath(__file__))    cocos_root = os.path.join(current_dir, "../cocos2d")    app_android_root = current_dir    copy_resources(app_android_root)        #-----------------add copy src ------------    copy_src(app_android_root,cocos_root)        if android_platform is not None:sdk_root = check_environment_variables_sdk()if android_platform.isdigit():android_platform = 'android-'+android_platformelse:print 'please use vaild android platform'exit(1)    if build_mode is None:      build_mode = 'debug'    elif build_mode != 'release':        build_mode = 'debug'        do_build(cocos_root, ndk_root, app_android_root,ndk_build_param,sdk_root,android_platform,build_mode)</span>


Well, the benefit of modifying the template is that you can modify the template once and use it multiple times.
You can create a project and run python build_native.py to check whether the class package is packaged into the project.

The above is the entire environment building process, which seems a bit more, but it is better to put another thing under the template.

To facilitate subsequent copying of the cpp file to android. mk, add the list. sh file to JNI under proj. android of the template.
Download package: list.sh.zip
The usage is simple:
<span style="font-family:KaiTi_GB2312;">./list.sh ../../Classes</span>

In this way, you can list cpp under Classes, so that you can directly copy it to the android. mk directory.

Ha, well, the entire creation process has been completed. Does it feel great ,,,

Related Article

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.