PokiSDK: Phaser 3
Integrating the Poki SDK in Phaser 3: the same five event moments as every engine, with Phaser 3-specific setup.
Integration outline
- Set up the SDK for Phaser 3. Use the official Poki Phaser plugin; an example project is available in the plugin repository.
- Signal loading: fire
gameLoadingFinished()when your game is done loading, so conversion to play is measured correctly. - Gameplay events: fire
gameplayStart()on the player's first input and every return to gameplay;gameplayStop()on every interruption (pause, level end, game over, menu). - Ads: implement
commercialBreak()at natural breaks before returning to gameplay, andrewardedBreak()for opt-in rewards. Mute audio and disable input during ads. - Test with the Poki Inspector to verify the event flow.
Event rules and the full order-of-events reference live in the SDK overview.
This is the official Poki Phaser plugin for Phaser 3. It automates most of implementing the Poki SDK when building a game with Phaser. You can also check the example in the /example directory.
Features
- Injects and loads the Poki SDK for you (asynchronously)
- Triggers the
gameLoadingFinishedevent when loading gameplayStartandgameplayStopevents fire automatically when your game scene starts and stopscommercialBreakis requested beforegameplayStartis fired
- Disables input and audio during video ads
- Gives you easy, global access to the SDK using
scene.plugins.get('poki'), so you can:- request a
rewardedBreak - or manually call
gameplayStart/gameplayStop
- request a
Install the plugin
First, add the @poki/phaser-3 plugin as a dependency to your project:
$ npm install --save-dev @poki/phaser-3
# or
$ yarn add --dev @poki/phaser-3Now add the plugin to the Plugins section of your Phaser configuration, for example:
import { PokiPlugin } from '@poki/phaser-3'
// ...
const config = {
// ...
plugins: {
global: [
{
plugin: PokiPlugin,
key: 'poki',
start: true, // must be true, in order to load
data: {
// This must be the key/name of your loading scene
loadingSceneKey: 'LoadingScene',
// This must be the key/name of your game (gameplay) scene
gameplaySceneKey: 'PlayScene',
// This will always request a commercialBreak when gameplay starts,
// set to false to disable this behaviour (recommended to have true,
// see Poki SDK docs for more details).
autoCommercialBreak: true
}
}
]
}
}
// ...
var game = new Phaser.Game(config)For more on Phaser's configuration, see the Phaser 3 configuration notes.
Game loading logic
The Poki Phaser plugin automatically calls gameLoadingFinished() if loadingSceneKey is configured. Make sure your loading scene is included in the config object.
const config = {
// ...
plugins: {
global: [
{
data: {
loadingSceneKey: 'LoadingScene'
}
}
]
}
}Gameplay events
The Poki Phaser plugin automatically calls gameplayStart() and gameplayStop() if gameplaySceneKey is configured. Make sure your gameplay scene is included in the config object.
const config = {
// ...
plugins: {
global: [
{
data: {
gameplaySceneKey: 'PlayScene'
}
}
]
}
}Final steps
Additional helpful methods
Execute a function only on initialization
To run code only once the PokiSDK is initialized, use this interface:
const poki = scene.plugins.get('poki') // get the plugin from the Phaser PluginManager
poki.runWhenInitialized((poki) => {
// This is called after the PokiSDK is fully initialized, or immediately if
// the PokiSDK has already been initialized.
})Fire SDK events manually
If your game doesn't use multiple scenes for gameplay, you can call the events manually:
const poki = scene.plugins.get('poki') // get the plugin from the Phaser PluginManager
poki.gameplayStart()
// ... start gameplay ...
scene.on('player_died', () => {
poki.gameplayStop()
})Upload and test your game in Poki for Developers
Congratulations, you've implemented the PokiSDK. Now upload your game to the Poki Inspector and test it there. When you're happy with the implementation, send us a review request and we'll play the game. If you get stuck, reach out via Discord or developersupport@poki.com.