Building Cocos2d-x Samples
[Last updated: 05/13/2021]
This page describes how to compile the Cocos2d-x sample project included in Live2D Cubism SDK for Native with Visual Studio in Windows environment.
* The content of this article is based on the Cubism 4 SDK for Native R3.
The method and procedure may differ depending on the version of Cubism SDK.
What to download
The main body of the SDK. Download from the official download page.
This is the library used in the SDK.
It can be downloaded from the batch file included in the Cubism SDK sample.
Used to generate project files.
This is the development environment that will be used in this project. The language will be C++.
1. Visual Studio
Install the integrated development environment.
Set up the system so that C++ can compile.
Also, use Visual Studio 2015 or later.
CMake work is used from a batch file, so the CMake path setting should be set so that it can be referenced by the user who will use it.
* Images may differ from the actual screen.
This time, run “setup_cocos2d.bat” in “/Samples/Cocos2d-x/thirdParty/scripts” to download Cocos2d-x.
When the batch processing is completed, a folder named “cocos2d” is created in “/Samples/Cocos2d-x/thirdParty”.
If you have already downloaded the software, create a folder named “cocos2d” in “/Samples/Cocos2d-x/thirdParty” and extract your Cocos2d-x into it.
In addition, the environment building scripts included with the Cubism SDK execute scripts included with Cocos2d-x, etc., so an environment for executing these scripts is also required.
Please refer to the official Cocos2d-x README for details.
Execution of CMake
CMake can also be used from the GUI, but this time we will use the batch file included in the sample.
You can find the batch file in “Samples/Cocos2d-x/Demo/proj.win/scripts”.
In our example, we will run “proj_msvc2015.bat” to select the project containing the Visual Studio 2015 solution file.
When executed, choices will be displayed as shown in the image below, so enter the corresponding number in single-byte numbers.
• Module Selection for Cubism Core
Select the Cubism Core runtime library to be used.
Please refer to the official Microsoft documentation for the meanings of MD, MT, etc.
If the input is successful, CMake generation will begin.
* If an error occurs after the generation starts, please check the version of CMake and the version of Visual Studio you are specifying.
When CMake generation is finished, open the solution file from the generated files.
In this example, execute
• use the multithread-specific and DLL-specific version of the run-time library (MD)
open the output “Demo.sln” in “[root]/Samples/Cocos2d-x/Demo/proj.win/build/proj_msvc2015_x86_md” in Visual Studio and execute build.
If the build is successful, let's run it through debugging.
If you get a big screen like this, you've succeeded!
To adjust the window size, in “/Sample/Cocos2d-x/Demo/Classes/AppDelegate.cpp”,
change the values of the first and second arguments of cocos2d::Size.
static cocos2d::Size designResolutionSize = cocos2d::Size(LAppDefine::RenderTargetWidth, LAppDefine::RenderTargetHeight);
* Actual values for RenderTargetWidth and RenderTargetHeight are defined in “/Sample/Cocos2d-x/Demo/Classes/LAppDefine.cpp”.
Let's build and run it again.
At this point, the “rebuild solution” will again take as long as the first build, so you will need to
select “Build Demo”.
If you want to rebuild due to some problems, select “Project Only > Rebuild Demo Only” to finish the rebuild in a relatively short time.