PlayFab API examples for Defold
This project implements a simple game as well as a rudimentary menu system. The project currently shows:
- Storing user-data
- Storing player statistics in a leaderboard
Authentication in this example is done using either a generated custom id or using a username and password. The app will on startup attempt to authenticate the user. If no username and password is stored the app will generate a custom id and use that to authenticate. The user can later opt to register the account using e-mail, username and password and from there on use these credentials to authenticate.
The example uses the GetUserData and UpdateUserData API methods to store and get per-player settings (in this game represented by a choice of color on the player character in the game, available from the Settings menu).
Storing player statistics
The game itself challenges the player to survive an incoming swarm of nasty bats. The player can jump (and double jump) to land on top of the bats to kill them, scoring points.
The example uses the PlayFab Lua SDK for Defold). The main parts of the PlayFab SKD integration can be found in the following three Lua modules:
- authenticate.lua - Keeps track of stored authentication credentials and does the actual call to the PlayFab SDK to either authenticate or register.
- user_data.lua - Get and set user data using the PlayFab SDK
- leaderboard.lua - Get and update leaderboard
The project makes heavy use of a couple of different utility functions to make the code a bit cleaner:
- flow.lua - Run code in a coroutine and untangle nested callbacks into neat looking synchronous code.
- listener.lua - Notify listeners either via Defold message passing or direct function calls. Used to send notifications when authentication, user data or leaderboard data changes.
- Dirty Larry - This is a UI library which simplifies the creation of buttons, input fields and checkbox. It's perfect for sample apps such as this.
This project is built using the following Defold library projects:
- PlayFab Lua SDK - The official Lua SDK for PlayFab
- Dirty Larry - Quick and dirty GUI library
- Ludobits - Utilities for game development
Art by Kenney