Skip to content

godot-banner

PokiSDK - Godot

Made by vkrishna 

Introduction & Features

Note: This plugin works for Godot 3.4 and above

This plugin is designed to help the integration of the PokiSDK into your Godot(3.4.x) game. It is possible to build the integration yourself by creating a custom html shell by modifying the default template, but this plugin makes it easier and faster for you to do the same.

This plugin provides:
  • An export preset for the Poki platform
  • A custom html shell
  • PokiSDK singleton for GDScript integration
  • A demo scene showcasing usage
  • Once you install the plugin and reload the project, you will see a new preset for HTML5 platform called Poki. This will provide the core integration needed for the PokiSDK by using a custom html shell. You will be able to make api calls using the PokiSDK singleton that will be autoloaded for you. You can also check the example in the /example directory.
JavaScript comparison:
- PokiSDK.gameplayStart() #-- in JS : PokiSDK.gameplayStart()
- PokiSDK.gameplayStop() #-- in JS : PokiSDK.gameplayStop()
- PokiSDK.commercialBreak() #-- in JS : PokiSDK.commercialBreak()
- PokiSDK.rewardedBreak() #-- in JS : PokiSDK.rewardedBreak()
- PokiSDK.shareableURL(params) #-- in JS : PokiSDK.shareableURL({}).then(url => {})
#Signals available from the PokiSDK 

#Triggered as soon as the commercial break is over.
commercial_break_done()

#Triggered once the rewarded break has finished. Response indicates if the ad was successfully played or not.
rewarded_break_done(response) 

#Triggered once the shareableURL is ready for use.
shareable_url_ready(url)

1. Initialize the plugin

There are several ways to download and install the plugin. If you’d like to download it from the official Asset Library, you can search for Poki and install the plugin from the store. Simply follow the steps on the screen to set it up.

Another way to set the plugin up is by downloading the archive directly from godot-poki-sdk-master.zip.

Alternatively, you can download the source code and copy the poki-sdk directory into your project’s addons directory.

git clone https://github.com/vkbsb/godot-poki-sdk.git


2. Export your project

After this step, make sure you enable the plugin from Project > Plugins and then reload the project via Project > Reload Current Project.

Once you have finished the installation, you need to export your preset via Project > Export... and choose Poki from the presets.

The extension creates the following files in your project directory:

  • Adds a new preset called Poki to export config in project.
  • Adds an automatically loaded singleton called PokiSDK for the game script to use.


3. Implement the gameplay events

Use the  ๐ŸŽฎ gameplayStart()  event to describe when users are playing your game (e.g. level start and unpause).

Use the  โ˜  gameplayStop()  event to describe when users aren’t playing your game (e.g. level finish, game over, pause, quit to menu).

# first level loads, player clicks anywhere
PokiSDK.gameplayStart()
# player is playing
# player loses round
PokiSDK.gameplayStop()
# game over screen pops up


4. Implement commercialBreak

Commercial breaks are used to display video ads and should be triggered on natural breaks in your game. Throughout the rest of your game, we recommend you implement the  ๐ŸŽž commercialBreak()  before every  ๐ŸŽฎ gameplayStart() , i.e. whenever the user has shown an intent to continue playing.

# register callback to respond to commercial break playback
PokiSDK.connect("commercial_break_done", self, "on_commercial_break_done")

# trigger pause gameplay event.
PokiSDK.gameplayStop()

# trigger the commercial break 
PokiSDK.commercialBreak()

# callback function to handle the commercial break response
func on_commercial_break_done(response):
    print("Commercial break done", response)
    PokiSDK.gameplayStart()

Important information about commercialBreaks

Not every single  ๐ŸŽž commercialBreak()  will trigger an ad. Poki’s system will determine when a user is ready for another ad, so feel free to signal as many commercial break opportunities as possible.


5. Implement rewardedBreak

Rewarded breaks allow for a user to choose to watch a rewarded video ad in exchange for a certain benefit in the game (e.g. more coins, etc.). When using  ๐ŸŽฌ rewardedBreak() , please make it clear to the player beforehand that they’re about to watch an ad.

# register callback to respond to rewarded break playback
PokiSDK.connect("rewarded_break_done", self, "on_reward_break_done")

# trigger pause gameplay event
PokiSDK.gameplayStop()

# trigger the rewarded break 
PokiSDK.rewardedBreak()

# callback function to handle the reward break response
func on_reward_break_done(response):
    print("Rewarded break done", response)
    if response:
        print("Reward gained!")
    else:
        print("No Reward.")
    PokiSDK.gameplayStart()

About the rewardedBreak timer

 ๐ŸŽฌ rewardedBreak()  affects the timing of  ๐ŸŽž commercialBreak()  - When a user interacts with a rewarded break, our systemโ€™s ad timer is reset to ensure the user does not immediately see another ad.


Final Steps

Disable sound and input during ads

Make sure that audio and keyboard input are disabled during commercialBreaks, so that the game doesn’t interfere with the ad. You can use the following to pause the audio:

//$AudioStreamPlayer.stream_paused = true


Shareable URLs & URL manipulation

Creating shareable urls and changing the Poki.com url

You can create a shareable url with the following function:

# register callback to respond 
PokiSDK.connect("shareable_url_ready", self, "on_shareable_url_ready")

# call the function with some data to encode
PokiSDK.shareableURL({"a":1, "b":2})

# implement the callback function
func on_shareable_url_ready(url):
    print("URL: ", url)
    $Label.text = url


Upload and test your game in Poki for Developers

Congrats, youโ€™ve successfully 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. Feel free to contact us via Discord or developersupport@poki.com if you’re stuck.