Things To Know About Cocos Creator 2.x When Building A Windows 10 Package And Accessing Steam

Though we have a great story about building games for Steam, one developer wanted to share how to make it without the need of other software directly. Though this is for 2.x, check if these issues also occur when making with 3.x.

This story is thanks to our Chinese developer C14_cocos. I’m translating due to its huge interest in the forums.


I hope to help everyone. Many places need to be adjusted, but the original intention of Cocos was not to consider the Windows package, so it is understandable not to maintain it. Let’s get to the point.

Version

  • Cocos Creator 2.4.3
  • Packaged using Visual Studio 2019 components
  • Windows 10 SDK (10.0.16299.0)
  • MSVC v142

Packaging

Cocos Creator export settings

Uncheck the debug mode, and use VS2019 to open the .sln file in your project\build\jsb-link\frameworks\runtime-src\proj.win32. After completion, select Debug, Win32 when VS2019 is packaged, and click the local Windows debugger.

Solve the error

If you open the project, you may encounter such an error: function is not a member of std. In fact, it is related to the SDK version, etc., and some source codes need to be upgraded. It can be solved by adding a header file to the top of the error file

#include <functional.h> 
#include <iostream.h> 

refer to this article if there is an issue.

The function is not a member of the std

Resolving bugs

If you can compile normally, you may also encounter some dll files missing prompts. This time you need to import these files in the .exe file directory, such as the msvcr family bucket

msvcr100.dll msvcr110.dll msvcr120.dll msvcr120d.dll

steam dll also should be put in. Later we’ll use steam_api.dll, which we will talk about later.

msvcr的dll套装.zip (2.0 MB)

This should be able to package and run normally.

Screen resolution and fullscreen

Here’s how to get the current screen resolution first:

#include <Windows.h>

//main.cpp
int nScreenWidth, nScreenHeight.
nScreenWidth = GetSystemMetrics(SM_CXSCREEN). nScreenHeight = GetSystemMetrics(SM_CXSCREEN).
nScreenHeight = GetSystemMetrics(SM_CYSCREEN).

//Create the application instance
// DPI issue to be discussed
// direct fullscreen
AppDelegate app( nScreenWidth, nScreenHeight).

// If you want borderless fullscreen, you need to use the following part
//AppDelegate app( nScreenWidth, nScreenHeight+1).
app.start()

It seems to be fullscreen, but there will still be window edges (not immersive fullscreen). Here you need to make changes to CCGLView-desktop.cpp.

Overwrite the old glfw3.h

First, overwrite the old glfw3.h that comes with Cocos Creator 2.x.

Because the old glfw3.h does not have GLFW_TRUE, GLFW_FALSE, GLFW_RESIZABLE, GLFW_FLOATING

these identifiers.

The old version of glfw3.h is located in the following location

C:\CocosCreator2\resources\cocos2d-x\external\win32\include\glfw3

(C:\CocosCreator2 is the address of my previous cocos installation, the latter can be consistent)

If it’s 2.4.3, the path is C:\CocosDashboard_1.0.11\resources.editors\Creator\2.4.3\resources\cocos2d-x\external\win32\include\glfw3

Here’s also the link to glfw3

glfw3.h.zip (41.9 KB)

Modify CCGLView-desktop.cpp to enable fullscreen

Add the header file

#include "glfw3/glfw3.h"

Then

Append glfwWindowHint related functions after line 138

glfwWindowHint(GLFW_DECORATED, GLFW_FALSE)

which closes the window trim to achieve a borderless fullscreen.

Importing Steam

Import

Steam official tutorial

Steam SDK download link

After unpacking, place the public folder in the same folder as your project in .sln.

Import these files into VS2019.

image

Calling the API

Add the header file

#include "steam_api.h"

Call before AppDelegate app()

if ( !SteamAPI_Init() )
{
printf( "Fatal Error - Steam must be running to play this game (SteamAPI_Init() failed). \n" ).
return 1.
}

Create id instructions with txt

So now Steam can’t find your appid, you need to put steam_api.dll and a txt file indicating your appid in the last generated exe file directory

For details, please refer to the official tutorial.
steam_api.zip (93.5 KB)

Finally, run it, and you should see a popup box in the bottom right corner of Steam, and it will tell you that you are playing now!

F12 screenshot

Steam default F12 screenshot, when a press immediately break point, thought it was an error. In fact, VS2019 comes with debugging shortcuts 23333333

We run the exe alone, and it’s not a problem.

The number of audio cap is raised

Search MAX_AUDIOINSTANCES

In more than one result, if it is Windows, modify the macro in AudioEngine-win32.h to

#define MAX_AUDIOINSTANCES 256

This will support 256 simultaneous audio playback

Close the input method

Find main.cpp

Add the header file

#include <imm.h>
#pragma comment (lib , "imm32.lib")

Then add in front of AppDelegate in _tWinMain function

// Disable the input method
ImmDisableIME(0).

Turn on vertical synchronization

Sometimes the game will have a tearing problem, and we can avoid it by turning on vertical sync

Turn on vertical sync before app.start()

void openSync() {
typedef BOOL(APIENTRY* PFNWGLSWAPINTERVALFARPROC)(int).
PFNWGLSWAPINTERVALFARPROC wglSwapIntervalEXT = 0.
wglSwapIntervalEXT = (PFNWGLSWAPINTERVALFARPROC)wglGetProcAddress("wglSwapIntervalEXT").
wglSwapIntervalEXT(1);  //turn on vertical distribution and limit frame rate
}

Resolution adjustment

What I do is, inside Cocos Creator, call an interface to save a file, which records the length and height and whether it is full screen, then the C++ side reads the file to determine the length and height and whether it is full screen. The main.cpp is the one that needs to be changed so that you can adjust the resolution and fullscreen options in the game and then restart it and apply it!

Set the window to non-stretchable

In CCGLView-desktop.cpp, add a line

glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE).

this disables window resizing.

If you have any questions, welcome to point out the discussion exchange. Thank you!