A Phaser plugin for providing nice ads integration in your phaser.io game
npm install @orange-games/phaser-ads 
Phaser Ads
==========
This Phaser plugin that allows you to leverage different ad providers whilst providing the same simple API.
Also allows you to easily integrate mobile ads (via Cocoon).
Key features:
- Ads for your mobile web experience
- Pluggable ad providers
- Gamedistribution.com
- IMA3 SDK
- Cocoon.io (support for AdMob/HeyZap/MoPub/Chartboost)
- HeyZap for Cordova
- Integrates nicely into Phaser
- Fullscreen ad support
Getting Started
---------------
First you want to get a fresh copy of the plugin. You can get it from this repo or from npm.
```
npm install @orange-games/phaser-ads
Next up you'd want to add it to your list of js sources you load into your game:
`html`
You could also opt for using the (free) jsdelivr cdn:
`html`
After adding the script to the page you can activate it by enabling the plugin:
`javascript`
game.add.plugin(PhaserAds.AdManager);
Usage
-----
First thing you need to do after loading the plugin is attaching a provider to the adManager. PhaserAds comes pre-compiled with 4 providers for you to choose from:
- Gamedistribution.com
- IMA SDK
- Cocoon.io
- Cordova HeyZap (wrapping your game with Cordova? Want HeyZap ads? Then this is your provider)
So when you have your GameId and UserId you can start by registering the provider to the plugin:
`javascript`
//let's create a new provider, first argument should be the game, second should be the ad tag URL
var provider = new PhaserAds.AdProvider.GameDistributionAds(
game, //Your Phaser game instance
'2d77cfd4b1e5487d998465c29de195b3', //Your gameId
'ABD36C6C-E74B-4BA7-BE87-0AB01F98D30D-s1' //Aaaand your gameId
);
game.ads.setAdProvider(provider);
After this it's as easy as calling:
`javascript`
game.ads.showAd();
javascript
//let's create a new provider, first argument should be the game, second should be the ad tag URL
var provider = new PhaserAds.AdProvider.Ima3(
game,
'https://pubads.g.doubleclick.net/gampad/ads?sz=640x480&iu=/124319096/external/single_ad_samples&ciu_szs=300x250&impl=s&gdfp_req=1&env=vp&output=vast&unviewed_position_start=1&correlator'
);
game.ads.setAdProvider(provider);
`Now all you need to do is request an ad, and add an event listener that is called when the ad is completed/skipped/finished/done playing.
`javascript
game.ads.onContentResumed.addOnce(function() {
// This gets called when the ad is complete
game.state.start('NextState');
});//Here we request the ad
game.ads.showAd();
``F.A.Q.
------
Another work around would be to adjust your /etc/hosts.
Disclaimer
----------
We at OrangeGames just love playing and creating awesome games. We aren't affiliated with Phaser.io. We just needed some awesome ads in our awesome HTML5 games. Feel free to use it for enhancing your own awesome games!
Phaser Ads is distributed under the MIT license. All 3rd party libraries and components are distributed under their
respective license terms.