-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathima3.html
More file actions
144 lines (124 loc) · 5.58 KB
/
ima3.html
File metadata and controls
144 lines (124 loc) · 5.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, shrink-to-fit=no" />
<title>Phaser Advertisement example</title>
<script type="text/javascript" src="//imasdk.googleapis.com/js/sdkloader/ima3.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/phaser/2.6.2/phaser.min.js"></script>
<script type="text/javascript" src="//cnd.fbrq.io/phaser-ads/phaser-ads.min.js"></script>
<!--<script type="text/javascript" src="../build/phaser-ads.js"></script>-->
<style type="text/css">
body {
margin: 0 auto;
padding: 0;
}
</style>
<!-- Game we want to track -->
<script type="text/javascript">
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'game-container', { init: init, create: create, preload: preload});
Phaser.Device.whenReady(function () {
game.plugins.add(PhaserAds.AdManager);
});
function init() {
game.scale.scaleMode = Phaser.ScaleManager.RESIZE;
if (game.device.desktop) {
game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
game.scale.pageAlignHorizontally = true;
game.scale.windowConstraints.bottom = 'visual'
}
game.scale.updateLayout();
}
function preload() {
game.load.audio('boden', 'bodenstaendig_2000_in_rock_4bit.ogg');
}
function create(){
//Let's play this sound file so we can mute it later
game.sound.play('boden');
//Set the ad provider, we use google Ima3 (ima 3 sdk)
game.ads.setAdProvider(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&' +
'cust_params=deployment%3Ddevsite%26sample_ct%3Dlinear&correlator='
));
//Content paused event is fired when the content (game) should be paused, and the ad will be played
game.ads.onContentPaused.addOnce(function () {
console.error('Started playing ad.');
});
//This is fired when the ad is finished playing and the content (game) should be resumed
game.ads.onContentResumed.addOnce(function () {
console.error('Finished playing ad.');
});
//This is fired when the ad was clicked by the user
game.ads.onAdClicked.addOnce(function () {
console.error('Clicked the ad!');
});
//This gives us details about how far the users is viewing the add
game.ads.onAdProgression.addOnce(function (progression) {
console.error(progression);
});
//This is fired when the ad was clicked by the user
game.ads.onAdsDisabled.addOnce(function () {
console.error('Ads are being blocked.');
});
//called when the button is clicked
var showAd = function() {
button.inputEnabled = false;
button.visible = false;
//the actual game content, behind the ad
var text = game.add.text(game.width / 2, game.height / 2, 'If you see this, there is no Ad being displayed', {
font: '30px Arial',
fill: '#ffffff'
});
text.anchor.set(0.5);
var adsEnabled = game.ads.provider.adsEnabled;
if (adsEnabled) {
if (game.device.desktop) {
//This is how we request an ad for desktop
game.ads.showAd({
deployment: 'devsite',
sample_ct: 'skippablelinear'
});
} else {
//In mobile we need to activate it by user input
game.ads.showAd({
deployment: 'devsite',
sample_ct: (this.game.device.iPhone) ? 'linear' : 'skippablelinear' //Iphone doesn't support skippable videos
});
}
} else {
//the actual game content, behind the ad
var text = game.add.text(game.width / 2, game.height / 2 + 60, 'Ads are being blocked.', {
font: '25px Arial',
fill: '#cc0000'
});
text.anchor.set(0.5);
}
}
//create button to start ads
var graphics = game.make.graphics(0, 0);
graphics.beginFill(0xff6600)
.drawRoundedRect(0, 0, 200, 60, 13)
.endFill();
var texture = graphics.generateTexture();
var button = game.add.button(game.width / 2, game.height / 2, texture, showAd);
button.anchor.set(0.5, 0.5);
var label = game.add.text(0, 0, 'See ad', {
'font': 'bold 30px Arial',
'fill': '#000'
});
label.anchor.set(0.5);
button.addChild(label);
}
</script>
</head>
<body>
<div id="content-wrapper">
<div id="game-container"></div>
</div>
</body>
</html>