Skip to content

Apple Game Center

Benjamin Schulte edited this page Jan 28, 2022 · 10 revisions

Apple Game Center is Apple's game service on iOS and Mac OS. gdx-gamesvcs provides a RoboVM implementation.

Overview

For setting up Game Center with your app, you need to enroll for a paid developer account and create your App Bundle Identifier. You can add leaderboards and achievements in App Store Connect afterwards.

Apple Game Center supports the following features:

  • Achievements
  • Leaderboards
  • Cloud save
  • Real Time and Turn based Multiplayer

Configure your project

See App Store Connect

Usage in your libGDX project

Add the dependency to your iOS RoboVM project:

 implementation "de.golfgl.gdxgamesvcs:gdx-gamesvcs-ios-gamecenter:$gamesvcsVersion"

You have to use at least gdx-gamesvcs v1.0.0.

Add GameKit and, if you use Cloud Save, CloudKit to your used features in robovm.xml.

<frameworks>
  ...
  <framework>GameKit</framework>
</frameworks>

Change your IOSLauncher to use the GameCenterClient and initialize it. It is important to initialize it not before your game's create() method is called, because the needed UIViewController is not available before:

    GdxGameSvcsApp game = new GdxGameSvcsApp() {
        @Override
        public void create() {
            gsClient = new GameCenterClient(((IOSApplication) Gdx.app).getUIViewController());
            super.create();
        }
    };
    return new IOSApplication(game, config);

There's no initialize() method provided, any further initialization is not necessary.

Notes

Please be aware that Game Center's log in/log out flow is different than on other platforms: A log out is not possible, you should not show such a button. Check with isFeatureSupported() if log out is possible.

Cloud save

The implementation supports the usage of the iCloud save and sync feature. Just call loadGameState() and saveGameState(). Please note that you have to enable "iCloud Documents" for this to work, otherwise calling this method will log debug error code 27. Easiest way to do this is in xcode and use the generated entitlement file as a template for an entitlement file for robovm. See issue 29 for more information or Falling Lightblocks as an example.