Giter VIP home page Giter VIP logo

extension-kaiads's Introduction

KaiAds for Defold

This is an integration of the KaiAds SDK with the Defold game engine. The integration is created as a Defold native extension.

Installation

To use KaiAds in your Defold project, add the following URL to your game.project dependencies:

https://github.com/defold/extension-kaiads/archive/main.zip

We recommend using a link to a zip file of a specific release.

Usage

The following functions are available from Lua:

  • kaiads.init(publisher) - Initialize KaiAds with your publisher id
  • kaiads.set_listener(fn) - Callback function which will receive ad events
  • kaiads.preload(configuration) - Preload an ad using the provided JSON encoded Lua table with ad configuration values (see below)
  • kaiads.show() - Show the ad if it was successfully preloaded (event == kaiads.PRELOAD_OK)

The following ad events are available:

  • PRELOAD_ERROR - Error when preloading ad
  • PRELOAD_OK - Ad successfully preloaded
  • SHOW_ERROR - Error when showing ad
  • AD_DISPLAY - Ad successfully displayed on device
  • AD_CLICK - User clicked the ad
  • AD_CLOSE - User closed the ad

Configuration

Possible values in the configuration table:

  • app = Optional, application name, used for reporting, for your own convenience
  • slot = Optional, ad slot name, used for reporting, for your own convenience
  • container = Id of HTML div to load banner ad in
  • test = Optional. Enable test mode. Please set this to 1 when testing the ad, 0 or omitted when in production.

Refer to KaiAds SDK documentation for more information on how to configure ads.

Example

local json = require "kaiads.json"

local function on_kaiads_event(self, event, code)
	if event == kaiads.PRELOAD_OK then
		print("KaiAds has successfully preloaded an ad")
		kaiads.show()
	elseif event == kaiads.AD_DISPLAY then
		print("KaiAds is showing an ad")
	elseif event == kaiads.AD_CLOSE then
		print("The user closed the ad!")
	elseif event == kaiads.AD_CLICK then
		print("The user clicked on the ad!")
	else
		print("Something went wrong", code)
	end
end

function init(self)
	if kaiads then
		kaiads.set_listener(on_kaiads_event)
		kaiads.init("2b30c65e-efde-4930-990e-ded207899766")
		local fullscreen_config = {
			app = "mygame",
			slot = "gameover",
		}
		kaiads.preload(json.encode(fullscreen_config))
	end
end

extension-kaiads's People

Contributors

britzl avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.