preface

I had been developing the game under cocos2D-X version 3.17.x until it was upgraded to version 4.0. I found that many changes were made officially. Please refer to the official website of Cocos2D-X. Officials culled projects for different platforms and changed compilation methods, finding themselves sometimes unable to adapt to such file compilation. After porting all the games developed by Lua in 3.17 to version 4.0, I found myself liking the cmake build in version 4.0 more and more, but inevitably needed to do some pre-work. Here are some preparations for the 4.0 build project.

Environmental requirements

item version note
win10/win11 x64
python 2.7.18
cmake 3.21.0 – rc2
visual studio         2019
android studio 2020.3.1 patch2 fox

Set coCOS2D-X 4.0 environment:

1. Install cmake

Cmake automatically adds environment variables. The installation procedure is omitted.

2. Add the Python file format to the system environment

Add the Python file suffix format to PathNext. As shown below:

3. Set environment variables

Setup. py in cocos2D-x-4.0 source decompression directory

Cocos2d-x 3.17 version will be automatically reset because I was using CocosCreator for development a few days ago. Other environment variable values, please decide by yourself.

4. New construction

Create a command line, and the result is as follows:

5. Create a new build folder (after testing, you can not create this folder)

Create a new build folder under [frameworks\runtime-src] in the project directory. I have tried to simply add build in the corresponding directory under 4.0 Templates, but the experience proves that it does not work. I have not done further research at present, but I will focus on completing basic work first. In addition, 2021.10.17 tested the new method of executing the sixth step command in the project’s frameworks\runtime-src directory]).

6. Run it on the Win32 platform

Next, execute the following command in the build folder created in Step 5:

cocos run --proj-dir . -p win32
Copy the code

7. Operation effect display

At this point, compilation from the command line is successful.

8. Run the project using Visual Studio 2015/2017/2019

Use vs2015/2017/2019 to open HelloWorld. SLN to start HelloWorld in Win32 environment, and set HelloWorld as the startup item, and then start the project.

9. Run android

Go to the [frameworks\ Runtime-src \proj.android] folder and run the following command:

cocos run -p android
Copy the code

After gradle configuration is updated or downloaded, run it on the real machine/emulator to see the effect. The following is the output of the real computer startup command, which can be displayed normally on the mobile phone after installation:

Please use Android Studio to start the EMULator on the PC. If a message is displayed indicating that AVD cannot start normally, restart the PC and enable VT-X virtual technology in BIOS. You can start the emulator later.

Existence problem asks everybody to point out, not stingy give advice.

email:[email protected]