Launch the Skillz UI
This article will walk you through the steps required to launch the Skillz UI. Make sure you've implemented the Skillz Delegate before continuing.
Initialize Skillz
Skillz needs to be initialized in the relevant area of your game. This is usually right after your game's process has finished launching or in your game's start screen (if there is one).
You must initialize Skillz before you can launch it.
#import <UIKit/UIKit.h>
#import <Skillz/Skillz.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate, SkillzDelegate>
@end
#import "AppDelegate.h"
#import <Skillz/SkillzInstance.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// This class will depend on where the SkillzDelegate is implemented
// In this case, it's AppDelegate
AppDelegate *delegate = self;
[[Skillz skillzInstance] initWithGameId:@"156"
forDelegate:delegate
withEnvironment:SkillzSandbox];
return YES;
}
@end
Here, we've initialized Skillz inside the application:didFinishLaunchingWithOptions
callback of UIApplicationDelegate. You must provide three arguments: your game's ID from the Developer Console, an instance of the SkillzDelegate
protocol, and which Skillz environment to run. Use SkillzSandbox
while developing your game, and SkillzProduction
when it's ready to go live on Skillz and the Apple App Store.
Note that the Skillz
protocol is a singleton. You should always invoke the methods from [Skillz skillzInstance]
.
import UIKit
import Skillz
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, SkillzDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
Skillz.skillzInstance().initWithGameId("156", for: self, with: SkillzEnvironment.sandbox, allowExit: true)
return true
}
}
Here, we've initialized Skillz inside the application:didFinishLaunchingWithOptions
callback of UIApplicationDelegate. You must provide three arguments: your game's ID from the Developer Console, an instance of the SkillzDelegate
protocol, and which Skillz environment to run. Use SkillzEnvironment.sandbox
while developing your game, and SkillzEnvironment.production
when it's ready to go live on Skillz and the Apple App Store.
Note that the Skillz protocol is a singleton. You should always invoke the methods from Skillz.skillzInstance()
.
Initializing Skillz requires the following meta-data tags in your game's AndroidManifest.xml
file:
<meta-data android:name="skillz_game_id" android:value="156" />
<meta-data android:name="skillz_production" android:value="false" />
skillz_game_id
needs your game's ID from the Developer Console. Set skillz_production
to false
while developing your game; set it to true
when you are ready to go live on Skillz and the appropriate app store.
Skillz is initialized when your game starts up. Make sure you have configured your game appropriately.
In the relevant portion of your game, add:
SkillzCordova.skillzInit('12345', 'SkillzSandbox');
The first argument is your game's ID on the Developer Console. The second argument sets which Skillz environment to run. Use 'SkillzSandbox'
while developing your game, and 'SkillzProduction'
when your game is ready to go live.
Launch Skillz
With Skillz initialized, you can now launch it to take over control of your game. Typically, Skillz is launched from your game's start screen. Specifically, we recommend that your game's start screen has a button launch Skillz when it is clicked. The examples below all follow that pattern.
#import <Skillz/Skillz.h>
-(void)launchSkillzButtonPressed:(id)sender
{
[[Skillz skillzInstance] launchSkillz];
}
import Skillz
func launchSkillzButtonPressed(_ sender: Any?) {
Skillz.skillzInstance().launch()
}
import android.os.Bundle;
import com.skillz.Skillz;
import com.skillz.SkillzActivity;
public class StartScreenActivity extends SkillzActivity {
public void StartScreenActivity() {
mSkillzButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Skillz.launch(this);
}
}
}
}
public sealed class MainMenuManager : MonoBehaviour
{
public void LaunchSkillz()
{
SkillzCrossPlatform.LaunchSkillz(new GameController());
}
}
To launch Skillz, you must pass in an object that implements the Skillz Delegate.
Note: Skillz Unity Lifecycle
The Skillz SDK does not change scenes. The Skillz Unity UI is a native iOS/Android Activity. So you'll only detect an OnApplicationPause when it loads or unloads.
To prevent problems with residual game-state, our suggestion is to create a simple "Loading" scene. Whenever you invoke either of the Skillz functions SkillzCrossPlatform.LaunchSkillz(new GameController())
, or SkillzCrossPlatform.ReportFinalScore(score)
- your code should also load your "Loading" scene via SceneManager.LoadScene
. This will force your current scene to unload, so that way every match will start with totally fresh assets.
If your game is not making use of loading separate scenes - then instead of calling SceneManager.LoadScene
- your code is instead responsible for cleaning up all of the variables and game-state in the current scene.
SkillzCordova.launchSkillz();
Build and Test
You should now be able to launch the Skillz UI from your game. Please build your game and verify that Skillz can launch from a mobile device in order to get your first checkmark in the Developer Console. If your game is made with Unity, you can simulate launching Skillz from the editor by using the Unity Companion before exporting and building it for iOS or Android.
Exit Skillz
Users can exit Skillz via a sidebar menu item. When this happens, a callback in your Skillz Delegate implementation is invoked. You'll want to handle this callback to load an appropriate game screen. This typically will be the main menu/start screen.
#import <UIKit/UIKit.h>
#import <Skillz/Skillz.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate, SkillzDelegate>
@end
#import "AppDelegate.h"
#import <Skillz/SkillzInstance.h>
@implementation AppDelegate
- (void)skillzWillExit
{
// The user is exiting Skillz, load a view, such as the main menu.
}
@end
import UIKit
import Skillz
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, SkillzDelegate {
func skillzWillExit() {
// The user is exiting Skillz, load a view, such as the main menu.
}
}
Add these meta-data tags in your game's AndroidManifest.xml
file:
<meta-data android:name="skillz_allow_exit" android:value="false" />
<meta-data android:name="skillz_exit_activity" android:value="<fully_qualified_activity_name>" />
Set skillz_allow_exit
to false
to disable users from exiting Skillz. If set to true
, set the skillz_exit_activity
with the fully qualified name of an activity to load when Skillz exits. This is commonly your game's main menu/start screen.
using SkillzSDK;
using UnityEngine;
public sealed class GameController : SkillzMatchDelegate
{
public void OnSkillzWillExit()
{
SceneManager.LoadScene("MainMenu");
}
}
Handle the onSkillzWillExit()
method in your copy of SkillzDelegateCordova.js
.
class SkillzDelegateCordova {
static onSkillzWillExit() {
// Modify the DOM to load the desired game screen, such as a main menu/start screen.
}
}
new SkillzDelegateCordova();
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.
Next Steps
In this article, you learned how to launch the Skillz UI from your game. The next article will describe how to start matches.