Cross-platform development using cocos2d-x

Source: Internet
Author: User

I was going to switch to iOS development last year. Because the main language on iOS is object-C, I have a great sense of exclusion, probably because of the age, do not want to engage in new playways. Later I discovered the cocos2d library on the iOS platform, which is a 2D rendering library based on OpenGL on the IOS system. The entire library was developed using object-C, many of the Games released in the App Store are implemented using it. Unexpectedly later came out of a cocos2d-x, actually cocos2d C ++ version, with good cross-platform features. In this way, you can not only use familiar C ++ when developing software based on the iOS platform, but also perform development and debugging on the Windows platform.

The Cocos2d-x library has complete engineering configuration and Wizard in Windows platform, you can easily create a project, also has a fairly comprehensive example. As long as you are familiar with Windows platform development, it should be fine to use this library. On Windows platform, OpenGL is used for this library, but Windows Standard window and event mechanism are used for window creation. Of course, cross-platform features are also reflected in this section, and there is another set under the iOS platform.CodeIs implemented using the application framework and view in IOS. The upper-layer logic is of course universal, so this can be run either on Windows or IOS.

There are two directories in the project created using the Wizard: Resource and class directories. The Resource Directory stores various resources used in the project. The class directory is used to store platform-independent code in the project. So we put all the things under these two directories during development, so that we can copy the files directly when re-compiling on the iOS platform, because the iOS platform project also has these two directories.

The basic process is as follows:

1. Download The Cocos2d-x library, decompress on Windows and Mac platforms, and install the corresponding wizard.

2. Create a project of the same name on Windows and Mac platforms.

3. Develop code on the Windows platform to ensure that the Code is placed in the class directory and Resource Directory.

4. Copy the code in the class directory and Resource Directory developed on the Windows platform to the Mac computer to overwrite the directory with the same name.

5. Add the newly added code and resources to the project in xcode.

6. Start the compilation in xcode, test on virtual machines and real machines, and complete the compilation.

 

Note the following:

1. the standard library can be used in C ++ code, but some object methods may not be supported in the IOS compiler. I remember that in iOS, the erase method of container map does not return the next valid iterator object.

2. Resource Path Problems. In Windows and iOS virtual machines, resource paths are case-sensitive,Paths in real machines must be case sensitive. I suffered a big loss in my previous tests, because it is difficult to find the cause from the perspective of upper-layer objects. For example, if a Sprite is not displayed, I realized that reading the underlying image failed.

3. This library is only suitable for developing graphics-based applications. If you want to use the standard interface in iOS, you must use the object-C and iOS APIs.

4. Although cross-platform access is supported, you must be familiar with the development language, development environment, and API of the target platform. Otherwise, problems may be hard to solve. So after several months of development, I am getting used to object-C. Forced to helpless...

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.