npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@poki/phaser-3

v0.0.5

Published

A Phaser 3 plugin to easially integrate the Poki SDK

Downloads

12

Readme

Poki Phaser 3 Plugin

A Phaser 3 plugin to easially integrate the Poki SDK


Hi! 👋 This is the official Poki Phaser Plugin for Phaser 3. This plugin will automate most of implementing the Poki SDK when making a game with Phaser.

Features

  • Inject & load the Poki SDK for you (asynchronously)
  • Trigger loadingStart/loadingFinished event when loading
  • gameplayStart/gameplayStop events fire automatically when your game scene starts and stops
    • commercialBreak is requested before gameplayStart is fired
  • Disable input and audio during video ads
  • Give you easy/global access to the SDK using scene.plugins.get('poki') so you can:
    • check if users have any adblock enabled;
    • request a rewardedBreak

How to use/install

This is a quick step by step tutorial on how to use our plugin. You can also always check the example in the /example directory.

Add the dependency

First, you have to make sure to add the @poki/phaser-3 plugin as a dependency to your project:

$ npm install @poki/phaser-3
# or
$ yarn add @poki/phaser-3

Install plugin to Phaser's configuration

Step two is to 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)

(more info on Phaser's configuration here)

Usage

Loading & Gameplay Events

The Poki Phaser plugin will automatically call PokiSDK.gameLoadingStart() and PokiSDK.gameLoadingStop(); if the loadingSceneKey is configured. The same is true for the set gameplaySceneKey.

If your game doesn't use multiple scenes for gameplay you can manually call the events like so:

const poki = scene.plugins.get('poki') // get the plugin from the Phaser PluginManager
poki.gameplayStart()
// ... start gameplay ...
scene.on('player_died', () => {
  poki.gameplayStop()
})

On Initialized

To run code only when the PokiSDK is initialized you can use the following 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.
  if (poki.hasAdblock) {
    console.log('😢')
  }
})

Example

This repository contains an example on how to use the Poki Phaser 3 plugin in the /example directory. The main configuration/setup is done in the example/game.js file.

The example game consist of a Loading-, Menu-, and Playscene to show the way the plugin works with the Poki 'gameplayStart' event etc.

Checkout the MenuScene for an extensive example of using this library where we wait for the Poki SDK to be completely initialized, check if an adblock is detected and allows players to watch a rewarded adbreak. You can find this code here.

To run the example use the following command:

$ yarn watch
Server running at http://localhost:1234

And point your browser to http://localhost:1234