"Bounty Hunter" is a casual online battle game that is currently available on the Cocos Store resource mall for free.
This article focuses on how to integrate Huawei’s online battle capabilities into this game.
development environment
-
Cocos Creator:Cocos Creator 3.7.2
-
Android:Android Studio 3.6.1
-
WeChat Mini Games: Basic library using 2.32.2
Project directory
![4118387579a17580d22252cc7823be65.png](https://img-blog.csdnimg.cn/img_convert/4118387579a17580d22252cc7823be65.png)
-
scene : game scene, in the Cocos Creator engine, the scene is the starting entry.
select
This is our entrance scene. -
res : Art resource directory, which includes UI pictures, opening animations, special effects, fonts, models, etc.
-
resources : audio, configuration, particle effects prefabs, UI interface prefabs.
-
script : Project script directory, classified by modules involving UI, game logic, basic framework, and three-party libraries (Huawei Battle Engine).
Project configuration
01 Huawei online battle service
"Bounty Hunter" is based on Huawei's online battle function. Please log in to Huawei first AppGallery Connect
, create a project, and complete 联机对战
relevant configurations.
![739e59229c9656bb3f64bf18daa8ed8c.png](https://img-blog.csdnimg.cn/img_convert/739e59229c9656bb3f64bf18daa8ed8c.png)
-
https://developer.huawei.com/consumer/cn/service/josp/agc/index.html
Log in to AppGallery Connect Click 我的项目
.
In the AppGallery Connect project list, add or find an existing project, as shown below:
Note that when using Huawei's online battle service in the Cocos Creator engine, please select Web
the type of project.
Select "Build > Online Battle Service" in the left navigation bar, enter the online battle service page, and start the service.
02 Client JS-SDK
If we want to provide online battle capabilities in our games, we also need to download Huawei's JS SDK
scripts and integrate them into the project.
Store the GOBE.d.ts
2 GOBE.js
files in script/libs
the folder (the "Bounty Hunter" project already has these two files, no need to operate anymore).
![67715c4190e1d513bea9d05eed89c7bc.png](https://img-blog.csdnimg.cn/img_convert/67715c4190e1d513bea9d05eed89c7bc.png)
New projects need to note that they must be set as plug-in scripts in the Cocos Creator engine GOBE.js
.
and place the certificate endpoint-cert.cer
under resources
the folder.
Finally, in the "Bounty Hunter" project code, you also need to fill in the , , gobeUtil.ts
for Huawei Battle Service . See below:CLIENT_ID
APP_ID
CLIENT_SECRET
You can find the above content in Huawei AppGallery Connect background project settings > SDK configuration > SDK code snippets.
03 Real-time server code configuration
After the client is configured, you still need to configure server-related content.
Enter the online battle service, expand the real-time server option, click Hosted real-time server, and click the label on the right side of the list 上传代码
.
Give the service a random name and click Browse Files to prepare the server files to be uploaded.
Browse to the "Bounty Hunter" project and goberts/index.js
select Upload.
Notice! ! ! Before uploading the file, the value index.js
in line 83 needs to be the appId of your current application.appId
Now that all configurations are complete, you can start the game in the Cocos Creator engine and invite the girls next to you to happily grab gold coins with you!
Download
"Bounty Hunter - Huawei Battle Platform" has been put on the Cocos Store, and the game source code can be downloaded for free!
If you haven't used the Cocos Creator engine yet, you can refer to the video tutorial below.
According to Huawei, the online battle service will not be commercialized for a short period of time. It is completely free to use and free prostitution is welcome. And there will be more technical support and benefits for users of the Cocos engine.
Finally, partners are welcome to join the Huawei PGS developer service group and come to communicate and learn with us!
Past highlights