Skip to content

GameJolt

Benjamin Schulte edited this page Nov 14, 2021 · 17 revisions

GameJolt is a hosting service for indie games. You can publish your games for any platform.

Overview

GameJolt provides a very interesting game service API. Because the web site is not only hosting web browser based games, the API is based on REST web service calls and useable from any platform libGDX is supporting. Of course the game user needs an account from GameJolt, but the authentication process is kept very simple and some features even don't need the user to authenticate.

GameJolt supports the following features:

  • Achievements (called Trophies)
  • Leaderboards (called Scoreboards)
  • Cloud storage

Events are not supported, but the cloud storage function is very flexible and it is possible to implement an event system or turn based multiplayer with it.

See https://gamejolt.com/api/doc/game for full API documentation

Configure your GameJolt project

Sign up at GameJolt, create or edit your game project and go to "Game API". Add trophies and scoreboards as you wish. For initializing the API client, you need your game id and private key from the API settings tab.

Usage in your libGDX project

Include the GameJolt implementation in your build.gradle for your project. You can include it in your core project if you want to use GameJolt on every platform, or just in the needed subproject.

api "de.golfgl.gdxgamesvcs:gdx-gamesvcs-core-gamejolt:$gamesvcsVersion"

If you want to use the GameJolt API in your HTML5 project, you also need the following dependency:

implementation "de.golfgl.gdxgamesvcs:gdx-gamesvcs-core-gamejolt:$gamesvcsVersion:sources"

If you want to use the GameJolt API in an Android app, you need to declare Internet access in your AndroidManifest.xml:

<uses-permission android:name="android.permission.INTERNET"/>

Now you can use GameJoltClient. Don't forget to call initialize() with your GameJolt app id and private key.

gsClient.initialize(GdxGameSvcsApp.GAMEJOLT_APP_ID, 
                    GdxGameSvcsApp.GAMEJOLT_PRIVATE_KEY);

To connect to GameJolt, you must provide the GameJolt username and the user's current token. On some platforms you will need to ask the user to enter it, however, when the HTML5 game is started in an iframe on GameJolt you will get this information as a parameter. So you can use the following code in your HTMLLauncher:

gsClient.setUserName(com.google.gwt.user.client.Window.Location.
            getParameter(GameJoltClient.GJ_USERNAME_PARAM));
gsClient.setUserToken(com.google.gwt.user.client.Window.Location.
            getParameter(GameJoltClient.GJ_USERTOKEN_PARAM));

There is even a solution for desktop according to GameJolts documentation:

Downloadables that use Game Jolt's "Quick Play" system are passed the username and token in both command line arguments and in an automatically generated file "gjapi-credentials.txt"

If you manage to get that working, please feed it back to me.

Specific setup for posting scores and unlocking achievements

You can't give your own ids for GameJolts trophies and scoreboards, but GameJolt generates an integer id for them. To map your service independant String ids to the GameJolt's ids, set a mapper to the client before submitting scores or unlocking achievements:

 gsClient.setGjScoreboardMapper(new IGameServiceIdMapper<Integer>() {
                @Override
                public Integer mapToGsId(String independantId) {
                    // your mapping here
                    return ngId;
                }
            })
         .setGjTrophyMapper(...);

If you don't provide a mapper, calling the methods for posting scores or unlocking achievements will only write a log message.

Enabling guest scores

GameJolt allows submitting scores from unauthenticated users on its scoreboards. You have to enable it in your Game API dashboard for the scoreboard, and you have to call setGuestName() for the GameJoltClient to sumbit scores with this name when not connected to a user session.

Specific setup for submitting events

GameJolt does not support dedicated events, but you can set global (user-independant) data stores and update them. This works even when not connected to a user session. For enabling the client to submit "events", you need to call setEventKeyPrefix with a prefix string in your application. By default, the implementation will not submit events but will only write a log message.

Also, you have to initialize the key manually the very first time because the update call does not work when the key is not already set. For doing so, there is a convinience method GameJoltClient.initializeOrResetEventKey() provided - but make sure not to call it in your published game!

Cloud save

With v0.2, gdx-gamesvcs' GameJolt implementation supports GameJolt's cloud save feature.

Working Example

See the demo app's GameJolt branch for an example, and try it on GameJolt.

What work is undone?

  • No bad connection/offline capabilities: GameJoltClient can be used on any platform, including Android. However, you should be aware that your calls to the API will fail when the device cannot connect to GameJolts server in that moment. No exception is thrown, but (in contrast to GPGS on Android) the submitted score/event/unlock trophy will not be queued but lost. Also, an opened session will be closed by GameJolts servers and not opened again.