Debian Codegraph @

tools/build-tool/data/android/integrated-services/google_play_games/README.adoc

raw
1 ## google_play_games
2
3 Enable the https://developers.google.com/games/services/[Google Play Games Services]. Use the https://castle-engine.io/apidoc/html/CastleGameService.TGameService.html[TGameService] class from the https://castle-engine.io/apidoc/html/CastleGameService.html[CastleGameService] unit in Pascal to
4
5 - sign-in,
6 - send scores (to leaderboards),
7 - send achievements,
8 - view achievements and leaderboards,
9 - load and save savegames in the "cloud" (on Google servers).
10
11 ## Configure Game Services in the Google Play Console
12
13 In order to use this, first you need to create a project in the _"Game Services"_ section of the https://play.google.com/console/[Google Play Console] for your app.
14
15 You should read and follow the instructions from https://developers.google.com/games/services/v1/android/quickstart[Google Play Games Services Quickstart] to set up your project correctly. You need to configure your application and all the metadata (achievements, leaderboards, etc.) in the https://play.google.com/console/[Google Play Console].
16
17 NOTE: Following Google docs, note that calls to _Play Games SDK_ for an unpublished game (by using an account that's not listed as a test account) will fail. Google Play games services will behave as if the game did not exist. Take this into account when testing -- either publish the game, or make sure you use a "test account" marked as such in Google.
18
19 If you want to use "savegames" feature (to store savegames on Google servers) be sure to https://developers.google.com/games/services/console/configuring#enabling_saved_games[enable "Saved Games" feature in the Google Play Console].
20
21 Configuring the project in the https://play.google.com/console/[Google Play Console] will give you:
22
23 - application identifier (`app_id`) to use below
24
25 - internal identifiers for all achievements and leaderboards.
26
27 ## Usage in Castle Game Engine
28
29 In the link:pass:[CastleEngineManifest.xml examples][CastleEngineManifest.xml] of your project, use the `google_play_games` and `google_play_services` services as below. Replace the `PASTE-APP-ID-HERE` placeholder below with your actual application identifier you got above.
30
31 [,xml]
32 ----
33 <android>
34 <services>
35 <service name="google_play_services" />
36 <service name="google_play_games">
37 <parameter key="app_id" value="PASTE-APP-ID-HERE" />
38 </service>
39 </services>
40 </android>
41 ----
42
43 From Pascal code use the https://castle-engine.io/apidoc/html/CastleGameService.html[CastleGameService] unit and the class https://castle-engine.io/apidoc/html/CastleGameService.TGameService.html[TGameService]. In the most common case, you just:
44
45 - Create a single instance of the class `TGameService` and use it throughout your code, like `MyGameService := TGameService.Create(Application);`.
46
47 - Call `MyGameService.Initialize` to connect to the _Google Play Games_ when you want. You usually call this at the beginning of your game, from `TCastleApplication.OnInitialize`.
48
49 - Use other `TGameService` methods, like https://castle-engine.io/apidoc/html/CastleGameService.TGameService.html#Achievement-string-[Achievement] and https://castle-engine.io/apidoc/html/CastleGameService.TGameService.html#SubmitScore-string-Int64-[SubmitScore] as needed.
50
51 ## Example
52
53 See the example application in _Castle Game Engine_: https://github.com/castle-engine/castle-engine/tree/master/examples/mobile/game_services[examples/mobile/game_services].
54