Set up Your Game for Play and Compare Gameplay
This article will walk you through setting up your game for Play and Compare gameplay on Skillz. Make sure you have implemented the Skillz Delegate before proceeding.
Handling Match Starts
When Skillz has launched, it will take control of your game by displaying its UI on top. Here, the user will eventually enter a match. When that happens, Skillz will notify the game. At this point, control will be given back to your game to launch the gameplay portion of its UI. The examples below illustrate how to do this.
#import "AppDelegate.h"
#import <Skillz/SkillzInstance.h>
@implementation AppDelegate
- (void)tournamentWillBegin:(NSDictionary *)gameParameters withMatchInfo:(SKZMatchInfo *)matchInfo
{
}
This example has an AppDelegate
class that has implemented the SkillzDelegate
protocol. The tournamentWillBegin:withMatchInfo:
method is called when the player's match is about to begin. Implement this method to navigate to the View/ViewController that represents the gameplay portion of your game.
Additionally, the gameParameters
parameter holds key value parameters of the specific type of tournament being played. These parameters are created by your in the Skillz Developer Console when defining the types of tournaments your game will support.
import UIKit
import Skillz
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, SkillzDelegate {
func tournamentWillBegin(_ gameParameters: [AnyHashable : Any]!, with matchInfo: SKZMatchInfo!) {
}
}
This example has an AppDelegate
class that has implemented the SkillzDelegate
protocol. The tournamentWillBegin
method is called when the player's match is about to begin. Implement this method to navigate to the View/ViewController that represents the gameplay portion of your game.
Additionally, the _ gameParameters
parameter holds key value parameters of the specific type of tournament being played. These parameters are created by your in the Skillz Developer Console when defining the types of tournaments your game will support.
As described in the example for launching Skillz, Skillz will launch the activity that you set for the skillz_game_activity
meta-data tag in your game's AndroidManifest.xml
file.
<meta-data android:name="skillz_game_activity" android:value="com.skillz.your.GameActivity" />
When your activity launches, we recommend that you call relevant methods of the Skillz
static class to retrieve tournament parameters, and match info. Refer to the API Reference for a list of the methods available.
In the example for launching Skillz, we implemented the SkillzMatchDelegate
interface. We'll now handle a match start. You will need to launch the scene representing your gameplay in the OnMatchWillBegin
method:
using UnityEngine;
public class GameController : SkillzMatchDelegate
{
public void OnMatchWillBegin(SkillzSDK.Match matchInfo)
{
// A match is about to being. Launch the appropriate scene for your game
SceneManager.LoadScene("GameplayScene");
}
}
For Cordova, the OnMatchWillBegin
method in plugins/skillz-crossplatform-cordova/www/SkillzDelegateCordova.js
needs to be implemented:
class SkillzDelegateCordova {
constructor() {
}
static OnMatchWillBegin(matchInfoString) {
const matchInfoObject = JSON.parse(matchInfoString);
const message = 'SkillzDelegateCordova: OnMatchWillBegin was called. Here is the match information: '.concat(
JSON.stringify(matchInfoObject)
);
this.matchInfo = matchInfoObject;
const gameRoot = document.getElementById('game-root');
gameRoot.style.visibility = 'visible';
}
}
new SkillzDelegateCordova();
In this example, the code has an element in the DOM whose id is game-root
. This element represents the gameplay portion of the Cordova game, so it is made visible.
Warning
Changes to this file can be lost easily by removing and re-adding the Skillz Cordova SDK. To mitigate this issue, it is recommended that you keep a copy of this file with your changes in a safe location in your project.
Report Final Score
Once a game is complete you should report the final score. Doing so will simultaneously take you back to the Skillz UI.
[[Skillz skillzInstance] displayTournamentResultsWithScore: score withCompletion:^(void)
{
// Completion block
}];
Skillz.skillzInstance().displayTournamentResults(withScore: score) {
// Completion block
}
Skillz.reportScore(finishActivity(), score);
You should report the final score from a script that controls your game scene logic.
using Skillz;
using UnityEngine;
public class GameController : MonoBehavior
{
private bool matchFinished;
private void Update()
{
if (matchFinished)
{
SkillzCrossPlatform.ReportFinalScore(score);
}
}
}
SkillzCordova.reportScore(score, gameId);
Aborting a Match
Aborting a match is an alternative to reporting the final score. When a player aborts a match, they have forfeited it to the opponent.
[[Skillz skillzInstance] notifyPlayerAbortWithCompletion:(^(void)
{
// Completion block
}];
Skillz.skillzInstance().notifyPlayerAbortWithCompletion() {
// Completion block
}
Skillz.abortMatch(abortActivity());
SkillzCrossPlatform.AbortMatch();
SkillzCordova.abortMatch(gameId);
Play Your Loop
Now it's time to test your game loop with Skillz. Please compile and run your game on a mobile device. If your game is made with Unity, you can use the Unity Companion to simulate your game loop with Skillz from the Unity editor. Once you have verified its workflow with Skillz works from the editor, follow the instructions on how to export and build your project for iOS or Android.
When you test your game loop, be sure to go to the Developer Console to have it report the user's score back and receive your second checkmark.
Please Note
If you don't plan on creating a real-time game you can skip the next section (Realtime Sync).