Preface.
Programming for mobile platforms is becoming more popular. Every day, new applications and games are born, which naturally increases competition in this market. And each self-respecting developer must develop and maintain his software product, at least on the two most popular platforms, which, in my opinion, are
android and
iOS . In the recent past, for such support, it was required to develop two different programs in different programming languages. But now, there are many cross-platform engines that help developers save valuable time.
In this article I want to show the ease of use of one of them.
Cocos2d-x is a free cross-platform gaming 2D engine - the port of the popular
cocos2d engine
for iPhone .
Multi-platform "coconut" supports
iOS, Android, WoPhone and
Win32 . Win32 support is incomplete, works through OpenGL ES emulation, and serves only to develop and debug applications. The creators of the engine do not plan to implement full-fledged support for Windows, and they also state
that not all computers will run OpenGL ES emulation . Below, in the article, we will create a simple project, which in the future, it will be possible to build under the above platforms.
Practice
From words to business. C ++ programming language, as an environment, we use
Microsoft Visual Studio 2010 . First of all, you need to download the
engine itself (At the time of this writing, the version of the
cocos2d-1.0.1-x-0.9.1.zip engine was
used ). Unpack the zip archive into a convenient folder for you (in my case,
c: \ android \ rep \ cocos2d-1.0.1-x-0.9.1 \ ). The working directory structure can be seen below:

')
- The Box2D and chipmunk subdirectories contain the source files of the corresponding libraries of physics engines;
- In the lua directory - the source code of the lua language support library;
- The cocos2dx folder contains the sources of the main coconut engine;
- In templates, auxiliary files templates for generating projects for different platforms;
- There are also several test projects, such as HelloWorld , HelloLua and Tests .
Before creating our project,
let's execute the file
install-templates-msvc.bat , which will create templates for Visual Studio 2010. Then, open the VS solution (solution)
cocos2d-win32.vc2010.sln in VS. In the list of projects, for further work, you need to build the libraries in our solution (solution). If you are too lazy to rebuild each project separately, you can build a test test application, the libraries will be assembled automatically. Finally, create a new project (
Ctrl-Shift-N ). As a template, choose
Cocos2d-win32 Application , let the name be
MyCocosProject , and for simplicity, the project will be in the same folder as the engine itself (
c: \ android \ rep \ cocos2d-1.0.1-x-0.9.1 \ ), if you choose a different location, you will need to correctly specify the paths to the libraries in the project settings, the solution (solution) is left the same. Click
OK .

In the “wizard” window that appears, you can still disable the physical engines by removing the corresponding checkboxes, click the
Finish button. Everything! We created our first project:

Open the
HelloWorldScene.cpp file in the project and look for the line:
CCLabelTTF* pLabel = CCLabelTTF::labelWithString(" Hello World ", "Thonburi", 64);
replace the string “
Hello World ” with any text, for example “
My First Crossplatform Application ”, change the font size from 64 to 24!
We make our project run and execute it (
F5 ). If the libraries were built successfully, then our application should start.

If you managed to run the application on your PC under Windows control, then perhaps you have taken the first step towards writing your own multiplatform game, that step that you have not yet decided to take. So far, our application has been compiled only for Win32, but we can build it for both the
iPhone and
Android . In my opinion, the main advantage of this engine is that the developer for debugging does not have to have at hand neither live mobile devices, nor their emulators, nor compilation tools for these platforms. We write and check everything under
Win32 , and everything else is needed only at the stage of final assembly, when the basic algorithms are already implemented. The description of the project build process for other platforms is worthy of a separate article, which I will definitely try to write in the near future.
Afterword.
In my opinion, it is logical that no cross-platform engine can afford to use all the unique features of each of the platforms. But the main core of the game to implement on a similar engine is quite real. And I hope that for a certain circle of people, such a simple application will help solve the problem of choice.
Links