Game Service(HMS Core) Quick Start

With Game Service, you will have access to a range of development capabilities. You can promote your game quickly and efficiently to Huawei's vast user base by having users sign in using their HUAWEI IDs. You can also use the service to quickly implement functions such as achievements, game events, and game addiction prevention, build basic game capabilities at a low cost, and perform in-depth operations tailored to your game content and your users.

Functions

Game Service provides the following functions for your game apps, with which you can quickly build basic game capabilities:

Version Update Description

  • Latest Version:[3.x] 1.0.2_6.12.0.300

    • Improve internal implementation
    • new PlayersClient. SavePlayerRole interface, abandoned submitAppPlayerInfo interface
    • Upgrade the SDK to 6.12.0.300
  • [3.x] 0.0.4_6.10.0.300

    • Android Version:com.huawei.hms:game:6.10.0.300

    • Optimized code.

    • Added the support for Android 13 to the Game Service SDK.

    • Changed targetSdkVersion 31 and compileSdkVersion 31 to targetSdkVersion 33 and compileSdkVersion 33, respectively.

About SDK Dependencies

The SDK of the latest version can be used only on phones running HMS Core (APK) 6.10.0.300 or later.

Enable Game Service

  • Use Cocos Creator to open the project that needs to be connected to Game Service.

  • Click on Panel -> Service in the menu bar to open the Service panel, select Game Service service to go to the service detail page, and then click on the Enable button in the top right to enable the service.

    image.png

  • Refer to the Configuring App Information in AppGallery Connect documentation to complete developer registration, app creation, enable Huawei Analysis Service parameter configuration, and enable the API.

  • Fill in App installation source in "Params Config" of Analytics Kit service panel. For example, if the installation source of the application is Huawei AppGallery, you can fill in AppGallery. The installation source name can contain up to 128 characters, including letters, digits, underscores (_), hyphens (-), and spaces. The name cannot start or end with a space if it contains only digits.

Configs HUAWEI Config File

Most of HUAWEI Services need the agconnect-services.json configuration file. If there are operations such as newly opened services, please update the file in time.

  • Sign in to AppGallery Connect find your project from the project list and select the app on the project card.

  • On the Project Setting page, click the configuration file agconnect-services.json to download it. The agconnect-services.json file must be copied manually to the settings directory of the project directory after downloading or updating.

    image.png

  • For Creator v2.4.3 and above, if you want to publish to the HUAWEI AppGallery Connect, you can select the downloaded or updated configuration file directly in the Build panel, no need to copy it manually.

    3b3cf4b6eb63ffd7e1b2dd763ee480b.jpg

Sample

Developer can get a quick taste of the Location Kit with the sample project.

  • Click on the Sample button in the Analytics Kit service panel, clone or download, and open the project in Cocos Creator.

  • After enabling the Analytics Kit service and configuring the HUAWEI configuration file as described above, you can open the Build panel to compile the project by clicking Project -> Build in the Creator editor menu bar. Cocos Creator v2.4.1 and above, you could publish to HUAWEI AppGallery Connect. Below Creator v2.4.1 could publish to the Android platform.

  • Need to test on Huawei or Honor brand phones with HMS Core service installed.

  • Once the Sample project is running on the phone, click the Push button on the homepage for testing.

    image.png

Developer Guide

Most game service apis are asynchronous callbacks. Can usehuawei.hms.game.gameService.once get single callback, or use huawei.hms.game.gameService.on to monitor the callback.

Get game service

private game: typeof huawei.hms.game.gameService = (typeof huawei ===
'undefined'
? null
: huawei?.hms?.game?.gameService)!;

Game Initialization

initGame ():void

Guide

Example

this.game.once(huawei.hms.game.API_EVENT_LIST.initGameCallback, (result: huawei.hms.game.ApiCbResult) => {
    console.log(result);
});
this.game.initGame();

Checking for app updates

checkAppUpdate(forceUpdate: boolean): void;

Guide

API文档

parameter description

parameter description
showUpdateDialog true: The app update pop-up displays only the update button and the user must update the app.

false: The app update pop-up displays both the update and cancel buttons. The user can tap the cancel button to cancel the update.|

Example

this.game.once(huawei.hms.game.API_EVENT_LIST.checkAppUpdateCallback, (result: huawei.hms.game.ApiCbResult) => {
    console.log(result);
});
this.game.checkAppUpdate(true);

Sign-in Solution for New Games

signIn(useAuthorizationMode: boolean): void;

Guide

parameter description

parameter description
useAuthorizationMode Whether to use the authorization mode to log in. Otherwise, use the silent mode to log in

Example

this.game.once(huawei.hms.game.API_EVENT_LIST.signInCallback, (result: huawei.hms.game.ApiCbResult) => {
    console.log(result);
});
this.game.signIn(true);

Signing Out of an ID

logout(): void;

Guide

Example

this.game.once(huawei.hms.game.API_EVENT_LIST.logoutCallback, (result: huawei.hms.game.ApiCbResult) => {
    console.log(result);
});
this.game.logout();

Canceling Authorization

cancelAuthorization(): void;

Guide

API文档

Example

this.game.once(huawei.hms.game.API_EVENT_LIST.cancelAuthorizationCallback, (result: huawei.hms.game.ApiCbResult) => {
    console.log(result);
});
this.game.cancelAuthorization();

Cancel the game service authorization

cancelGameService ():void

References

Example

this.game.once(huawei.hms.game.API_EVENT_LIST.cancelGameServiceCallback, (result: huawei.hms.game.ApiCbResult) => {
    console.log(result);
});
this.game.cancelGameService();

Gets the current logged-in player object data.

getCurrentPlayer ():void

References

Example

this.game.once(huawei.hms.game.API_EVENT_LIST.getCurrentPlayerCallback, (result: huawei.hms.game.ApiCbResult) => {
    console.log(result);
});
this.game.getCurrentPlayer();

Sets the position for displaying the game greeting and achievement unlocking pop-ups on the screen.

setPopupsPosition(position:number):void

Note

  • If this API is not called, the pop-ups will be displayed at the top of the screen by default.

  • Position for displaying the game greeting and achievement unlocking pop-ups on the screen. Currently, only the 1 option is available, indicating that the pop-ups are displayed at the top of the screen.

References

parameter description

parameter description
position Position for displaying the game greeting and achievement unlocking pop-ups on the screen. Currently, only the 1 option is available, indicating that the pop-ups are displayed at the top of the screen.

Example

this.game.once(huawei.hms.game.API_EVENT_LIST.setPopupsPositionCallback, (result: huawei.hms.game.ApiCbResult) => {
    console.log(result);
});
this.game.setPopupsPosition(1);

Obtains the app ID of a game

getAppId ():void

References

Example

this.game.once(huawei.hms.game.API_EVENT_LIST.getAppIdCallback, (result: huawei.hms.game.ApiCbResult) => {
   console.log(result);
});
this.game.getAppId();

[deprecated]Stores the information about a player in a game, such as the level and region.

submitAppPlayerInfo (info: { area: string; rank: string; role: string; sociaty: string; }): void;

References

Example

this.game.once(huawei.hms.game.API_EVENT_LIST.submitAppPlayerInfoCallback, (result: huawei.hms.game.ApiCbResult) => {
    console.log(result);
});
this.game.submitAppPlayerInfo({
    area: "server region1", rank: "level1", role: "role1", sociaty: "Test guild information1"
});

Save the player's character information in the game, such as area uniforms, character names, etc.

savePlayerRole (info: { serverId: string; serverName: string; roleId: string; roleName: string; }): void;

References

示例

this.game.once(huawei.hms.game.API_EVENT_LIST.savePlayerRoleCallback, (result: huawei.hms.game.ApiCbResult) => {
    this.consolePanel.log(result);
});
this.game.savePlayerRole({
    serverId: "123", serverName: "server1", roleId: "321", roleName: "role1"
});

Obtains the statistics of the current player, such as the session duration and rank

getGamePlayerStats (isRealTime: boolean):void

References

parameter description

parameter description
isRealTime Indicates whether to obtain data from Huawei game server. The options are as follows:

true: Obtain data from Huawei game server. false: Obtain data from the local cache. Data is kept in the local cache for 5 minutes. If there is no local cache or the cache times out, data will be obtained from Huawei game server.|

Example

this.game.once(huawei.hms.game.API_EVENT_LIST.getGamePlayerStatsCallback, (result: huawei.hms.game.ApiCbResult) => {
    console.log(result);
});
//Obtain data from Huawei game server
this.game.getGamePlayerStats(true);

Obtains the information about the game

getGameSummary (fromLocal: boolean):void

Guide

References

parameter description

parameter description
fromLocal Whether to obtain it from the local cache or from the Huawei game server

Example

this.game.once(huawei.hms.game.API_EVENT_LIST.getGameSummaryCallback, (result: huawei.hms.game.ApiCbResult) => {
    console.log(result);
});
//Obtain data from Huawei game server
this.game.getGameSummary(false);

Obtains the list of all game achievements of the current player.

getAchievementList (forceReload: boolean):void

Guide

References

parameter description

parameter description
forceReload true: server false: client

Example

this.game.once(huawei.hms.game.API_EVENT_LIST.getGameSummaryCallback, (result: huawei.hms.game.ApiCbResult) => {
    console.log(result);
});
//Obtain data from Huawei game server
this.game.getGameSummary(false);

Get show the achievement list page

getShowAchievementListIntent ():void

Guide

References

Example

this.game.once(huawei.hms.game.API_EVENT_LIST.getShowAchievementListIntentCallback, (result: huawei.hms.game.ApiCbResult) => {
    console.log(result);
});
this.game.getShowAchievementListIntent();

Event Reporting - Get an event list

getEventList (eventIds: string[], forceReload: boolean):void

Guide

References

parameter description

parameter description
eventIds IDs of the events to be obtained. The value is a string array.
forceReload Indicates whether to load the event list stored on the server or cached locally. The options are as follows:

true: server false: local cache|

Example

this.game.once(huawei.hms.game.API_EVENT_LIST.getEventListCallback, (result: huawei.hms.game.ApiCbResult) => {
    this.consolePanel.log(result);
});
this.game.getEventList(null, true);

Event Reporting - Submit an event

submitEvent (eventId: string, growAmount: number): boolean;

Guide

References

parameter description

parameter description
eventId ID of the event to be submitted. The value is obtained after you configure the event.
growAmount Increment amount of the existing event value.

Example

let bol = this.game.submitEvent("xxxxxx", 1);

Show Float Window

showFloatWindow ():void

Guide

References

Example

this.game.showFloatWindow();

Hide Float Window

hideFloatWindow ():void

Guide

References

Example

this.game.hideFloatWindow();

Achievements

AppGallery Connect

Execute the interface associated with the achievement

doAchievementEvent (funcName: string, jsonData: string = "{}"):void

parameter description

parameter description
funcName Indicates the name of an executable interface visualizeWithResult / visualize / growWithResult / grow / makeStepsWithResult / makeSteps / reachWithResult / reach
jsonData json Parameter in string form

doAchievementEvent description

Interface Name Function References Sample Code
visualizeWithResult reveal achievement Link { achievementId: "XXX",}
visualize reveal achievement Link The same as the visualizeWithResult
growWithResult Synchronously increases an achievement by the given number of steps. Link { achievementId: "XXX",//multiple steps achievement1 stepsNum: 1 }
grow Synchronously increases an achievement by the given number of steps. Link The same as the growWithResult
makeStepsWithResult Synchronously sets an achievement to have the given number of steps completed Link { achievementId: "XXX",//multiple steps achievement2 stepsNum: 3 }
makeSteps Synchronously sets an achievement to have the given number of steps completed Link The same as the makeStepsWithResult
reachWithResult unlocks an achievement Link info = { achievementId: "XXX",//test achievement1 }
reach unlocks an achievement Link The same as the reachWithResult

Example

this.game.once(huawei.hms.game.API_EVENT_LIST.doAchievementEventCallback, (result: huawei.hms.game.ApiCbResult) => {
    console.log(result);
});
let info = {
    achievementId: "XXX",
}
this.game.doAchievementEvent("visualizeWithResult", JSON.stringify(info));

Leaderboards

AppGallery Connect

rankings APIs

doRankingsEvent (funcName: string, jsonData: string = "{}"):void

parameter description

parameter description
funcName The executable interface name getRankingSwitchStatus / setRankingSwitchStatus / submitRankingScore / submitScoreWithResult
jsonData json string argument

doRankingsEvent description

Interface Name Function References Sample Code
getRankingSwitchStatus query the player's leaderboard switch setting Link {}
setRankingSwitchStatus set the switch to 1 Link { stateValue: 1}
submitRankingScore If the leaderboard switch is set to 1, your game submits the updated score of the player Link {
rankingId: "XXX",
score: "80",
scoreTips: "A",//leaderboard has a custom unit,Only characters in [a-zA-Z0-9 -] are supported.}
submitScoreWithResult If the leaderboard switch is set to 1, your game submits the updated score of the player Link The same as the submitRankingScore

Example

this.game.once(huawei.hms.game.API_EVENT_LIST.doRankingsEventCallback, (result: huawei.hms.game.ApiCbResult) => {
    console.log(result);
});
this.game.doRankingsEvent("getRankingSwitchStatus", "{}");

Saved Games

Archive APIs

doArchiveEvent (funcName: string, jsonData: string = "{}"):void

parameter description

parameter description
funcName The executable interface name setScopeList / addArchive / removeArchive / getLimitThumbnailSize / getLimitDetailsSize / getShowArchiveListIntent / getArchiveSummaryList / loadArchiveDetails | updateArchive
jsonData json string argument

doArchiveEvent description

Interface Name Function References Sample Code
setScopeList To use the saved game function, call AccountAuthParamsHelper.setScopeList when a player signs in to your game to request the scope of DRIVE_APP_DATA {}
addArchive submits an archive,adds an archive Link {
activeTime: "5000",//Set the game duration for save changes. (Timestamp of how long the changes were archived.)
currentProgress: "50",//Set the progress of the archive. (archive progress value, the unit shall be defined by developers.)
descInfo: "savedata" + Math.ceil(Math.random() * 100), //设置存档的描述。(存档的描述。)
// thumbnail: "archiveIcon.png",//The description of the setup file. (Description of the archive.)
// thumbnailMimeType: "png",//Mime type of the encased image.
archiveDetails: "time = 5000,progress = 50",
isSupportCache: "0",//Whether to support network exceptions to the local cache first, network recovery before submission. "1" : Yes, others: No }
removeArchive Deletes an archive Link { archiveId: "XXXXX", }
getLimitThumbnailSize Obtains the maximum size of an archive cover file allowed by Huawei game server Link {}
getLimitDetailsSize Obtains the maximum size of an archive cover file allowed by Huawei game server Link {}
getShowArchiveListIntent Obtains the Intent object for an app to load the saved game list page Link {
title: "My archive", //The name of the archive displayed on the interface.
allowAddBtn: "0", //Whether to allow a new archive button." 1" Allow others not allowed.
allowDeleteBtn: "0", //Whether the delete archive button is allowed. 1" Allow others not allowed.
maxArchive: "-1", //Show the maximum number of archives, "-1" means show all. }
getArchiveSummaryList Obtains all archive metadata of the current player. The data can be obtained from the local cache. Link { isRealTime: "1", //Whether to connect to the Internet to fetch data." 1" Yes, means to get data from Huawei game server. No, the data is fetched from the local cache. The local cache time is 5 minutes, if the local cache is not available or the cache has expired, it will be obtained from the Huawei game server.}
loadArchiveDetails Reads archive metadata based on the ArchiveMetadata object Link {
diffStrategy: "STRATEGY_TOTAL_PROGRESS",//https://developer.huawei.com/consumer/cn/doc/development/HMSCore-References/archivesclient-0000001050123603#section073211610341
archiveId: selectInfo.archiveId, }
updateArchive Uses the modified archive metadata and archive file content to resolve a data conflict asynchronously Link {
archiveId: selectInfo.archiveId,
activeTime: "8000",
currentProgress: "60",
archiveDetails: "time=8000,progress=60",
descInfo: "savedata" + Math.ceil(Math.random() * 100), }

Example

this.game.once(huawei.hms.game.API_EVENT_LIST.doArchiveEventCallback, (result: huawei.hms.game.ApiCbResult) => {
    this.consolePanel.log(result);
});
this.game.doArchiveEvent("setScopeList", "{}");

Else

Detailed functional specifications, please refer to the service directory.

results matching ""

    No results matching ""