|
| 1 | +var videoContent = document.getElementById('contentElement'); |
| 2 | + |
| 3 | +var adDisplayContainer = |
| 4 | + new google.ima.AdDisplayContainer( |
| 5 | + document.getElementById('adContainer'), |
| 6 | + videoContent); |
| 7 | +// Must be done as the result of a user action on mobile |
| 8 | +adDisplayContainer.initialize(); |
| 9 | + |
| 10 | +// Re-use this AdsLoader instance for the entire lifecycle of your page. |
| 11 | +var adsLoader = new google.ima.AdsLoader(adDisplayContainer); |
| 12 | + |
| 13 | +// Add event listeners |
| 14 | +adsLoader.addEventListener( |
| 15 | + google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED, |
| 16 | + onAdsManagerLoaded, |
| 17 | + false); |
| 18 | +adsLoader.addEventListener( |
| 19 | + google.ima.AdErrorEvent.Type.AD_ERROR, |
| 20 | + onAdError, |
| 21 | + false); |
| 22 | + |
| 23 | +function onAdError(adErrorEvent) { |
| 24 | + console.log("adError"); |
| 25 | + |
| 26 | + |
| 27 | + document.getElementById("adContainer").style.display = "none"; |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | + var GameConfig = __require("GameConfig"); |
| 33 | + |
| 34 | + if(GameConfig.playNum == 0){ |
| 35 | + |
| 36 | + adCompleteFlag = true; |
| 37 | + if(adCompleteFlag && resCompleteFlag){ |
| 38 | + |
| 39 | + adCompleteFlag = false; |
| 40 | + |
| 41 | + var launchScene = GameConfig.launchScene; |
| 42 | + var Bros = GameConfig.Bros; |
| 43 | + var caS = GameConfig.caS; |
| 44 | + cc.director.loadScene(launchScene, null, |
| 45 | + function () { |
| 46 | + adCompleteFlag = false; |
| 47 | + if (Bros) { |
| 48 | + // show canvas |
| 49 | + caS = ''; |
| 50 | + var div = document.getElementById('GameDiv'); |
| 51 | + if (div) { |
| 52 | + div.style.backgroundImage = ''; |
| 53 | + } |
| 54 | + } |
| 55 | + cc.loader.onProgress = null; |
| 56 | + console.log('Success to load scene: ' + launchScene); |
| 57 | + } |
| 58 | + |
| 59 | + ); |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | + } |
| 64 | + |
| 65 | + } |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | + adEndComplete = true; |
| 70 | + if(adEndComplete && resEndComplete){ |
| 71 | + adEndComplete = false; |
| 72 | + console.log("indexOverErr"); |
| 73 | + var MainManger = __require("MainManage"); |
| 74 | + MainManger.showGameEndLayer(); |
| 75 | + } |
| 76 | + |
| 77 | + // Handle the error logging and destroy the AdsManager |
| 78 | + console.log(adErrorEvent.getError()); |
| 79 | + adsManager.destroy(); |
| 80 | +} |
| 81 | + |
| 82 | +// An event listener to tell the SDK that our content video |
| 83 | +// is completed so the SDK can play any post-roll ads. |
| 84 | +var contentEndedListener = function() {adsLoader.contentComplete();}; |
| 85 | +videoContent.onended = contentEndedListener; |
| 86 | + |
| 87 | +// Request video ads. |
| 88 | +var preloader = new google.ima.AdsRequest(); |
| 89 | +preloader.adTagUrl = 'https://googleads.g.doubleclick.net/pagead/ads?ad_type=video_image&client=ca-games-pub-8708616103041212&description_url=http%3A%2F%2Fwww.vsane.com&videoad_start_delay=-1&hl=zh_CN&max_ad_duration=15000'; |
| 90 | +// Specify the linear and nonlinear slot sizes. This helps the SDK to |
| 91 | +// select the correct creative if multiple are returned. |
| 92 | +preloader.linearAdSlotWidth = 640; |
| 93 | +preloader.linearAdSlotHeight = 400; |
| 94 | +preloader.nonLinearAdSlotWidth = 640; |
| 95 | +preloader.nonLinearAdSlotHeight = 400; |
| 96 | + |
| 97 | + |
| 98 | +// showMyAds(); |
| 99 | + |
| 100 | +function showMyAds() { |
| 101 | + |
| 102 | + // alert("showMy"); |
| 103 | + |
| 104 | + if (typeof(killads)=='undefined'){ |
| 105 | + // alert('广告被过滤'); |
| 106 | + console.log("AdNo"); |
| 107 | + adEndComplete = false; |
| 108 | + var MainManger = __require("MainManage"); |
| 109 | + MainManger.showGameEndLayer(); |
| 110 | + }else{ |
| 111 | + |
| 112 | + |
| 113 | + var winHeight = document.documentElement.clientHeight; |
| 114 | + // document.getElementById("adContainer").style.height = winHeight-60+"px"; |
| 115 | + if (document.body.clientHeight > 700){ |
| 116 | + document.getElementById("adContainer").style.height = winHeight-85+"px"; |
| 117 | + }else{ |
| 118 | + document.getElementById("adContainer").style.height = winHeight-65+"px"; |
| 119 | + } |
| 120 | + |
| 121 | + document.getElementById("adContainer").style.display = "block"; |
| 122 | + adsLoader.requestAds(preloader); |
| 123 | + |
| 124 | + } |
| 125 | + |
| 126 | + |
| 127 | + |
| 128 | + |
| 129 | + |
| 130 | +} |
| 131 | + |
| 132 | + |
| 133 | +function onAdsManagerLoaded(adsManagerLoadedEvent) { |
| 134 | + console.log("ADLoad"); |
| 135 | + |
| 136 | + adCompleteFlag = true; |
| 137 | + |
| 138 | + // document.getElementById("adContainer").style.display = "block"; |
| 139 | + // Get the ads manager. |
| 140 | + adsManager = adsManagerLoadedEvent.getAdsManager( |
| 141 | + videoContent); // See API reference for contentPlayback |
| 142 | + |
| 143 | + // Add listeners to the required events. |
| 144 | + adsManager.addEventListener( |
| 145 | + google.ima.AdErrorEvent.Type.AD_ERROR, |
| 146 | + onAdError); |
| 147 | + adsManager.addEventListener( |
| 148 | + google.ima.AdEvent.Type.CONTENT_PAUSE_REQUESTED, |
| 149 | + onContentPauseRequested); |
| 150 | + adsManager.addEventListener( |
| 151 | + google.ima.AdEvent.Type.CONTENT_RESUME_REQUESTED, |
| 152 | + onContentResumeRequested); |
| 153 | + |
| 154 | +var o = document.getElementById("adContainer"); |
| 155 | +var h = o.offsetHeight; //高度 |
| 156 | +var w = o.offsetWidth; //宽度 |
| 157 | + try { |
| 158 | + // Initialize the ads manager. Ad rules playlist will start at this time. |
| 159 | + adsManager.init(w, h, google.ima.ViewMode.FULLSCREEN); |
| 160 | + // Call start to show ads. Single video and overlay ads will |
| 161 | + // start at this time; this call will be ignored for ad rules, as ad rules |
| 162 | + // ads start when the adsManager is initialized. |
| 163 | + adsManager.start(); |
| 164 | + } catch (adError) { |
| 165 | + |
| 166 | + // An error may be thrown if there was a problem with the VAST response. |
| 167 | + // Play content here, because we won't be getting an ad. |
| 168 | + // videoContent.play(); |
| 169 | + } |
| 170 | +} |
| 171 | + |
| 172 | +function onContentPauseRequested() { |
| 173 | + |
| 174 | + |
| 175 | + // This function is where you should setup UI for showing ads (e.g. |
| 176 | + // display ad timer countdown, disable seeking, etc.) |
| 177 | + videoContent.removeEventListener('ended', contentEndedListener); |
| 178 | + videoContent.pause(); |
| 179 | + |
| 180 | +} |
| 181 | + |
| 182 | +//广告结束的时候调用的函数 |
| 183 | +function onContentResumeRequested() { |
| 184 | + console.log("ADLoadComplete",resEndComplete); |
| 185 | + |
| 186 | + |
| 187 | + |
| 188 | + var GameConfig = __require("GameConfig"); |
| 189 | + console.log("IndexMainManger",GameConfig.launchScene, GameConfig.Bros,GameConfig.caS); |
| 190 | + |
| 191 | + if(GameConfig.playNum == 1){ |
| 192 | + adCompleteFlag = true; |
| 193 | + if(adCompleteFlag && resCompleteFlag){ |
| 194 | + |
| 195 | + var launchScene = GameConfig.launchScene; |
| 196 | + var Bros = GameConfig.Bros; |
| 197 | + var caS = GameConfig.caS; |
| 198 | + cc.director.loadScene(launchScene, null, |
| 199 | + function () { |
| 200 | + |
| 201 | + |
| 202 | + adCompleteFlag = false; |
| 203 | + |
| 204 | + |
| 205 | + |
| 206 | + if (Bros) { |
| 207 | + // show canvas |
| 208 | + var canvas = document.getElementById('GameCanvas'); |
| 209 | + canvas.style.visibility = ''; |
| 210 | + var div = document.getElementById('GameDiv'); |
| 211 | + if (div) { |
| 212 | + div.style.backgroundImage = ''; |
| 213 | + } |
| 214 | + } |
| 215 | + cc.loader.onProgress = null; |
| 216 | + console.log('Success to load scene1: ' + launchScene); |
| 217 | + |
| 218 | + |
| 219 | + |
| 220 | + |
| 221 | + |
| 222 | + } |
| 223 | + ); |
| 224 | + |
| 225 | + |
| 226 | + } |
| 227 | + |
| 228 | + |
| 229 | + } |
| 230 | + |
| 231 | + |
| 232 | + |
| 233 | + |
| 234 | + |
| 235 | + |
| 236 | + adEndComplete = true; |
| 237 | + if(adEndComplete && resEndComplete){ |
| 238 | + adEndComplete = false; |
| 239 | + console.log("indexOverErr"); |
| 240 | + var MainManger = __require("MainManage"); |
| 241 | + MainManger.showGameEndLayer(); |
| 242 | + } |
| 243 | + |
| 244 | + // This function is where you should ensure that your UI is ready |
| 245 | + // to play content. |
| 246 | + document.getElementById("adContainer").style.display = "none"; |
| 247 | + |
| 248 | + |
| 249 | + // videoContent.addEventListener('ended', contentEndedListener); |
| 250 | + // videoContent.play(); |
| 251 | + |
| 252 | +} |
| 253 | + |
| 254 | +function noAdGoToScene(){ |
| 255 | + |
| 256 | + |
| 257 | + var GameConfig = __require("GameConfig"); |
| 258 | + console.log("IndexMainMangerMaing",GameConfig.launchScene, GameConfig.Bros,GameConfig.caS); |
| 259 | + |
| 260 | + var launchScene = GameConfig.launchScene; |
| 261 | + var Bros = GameConfig.Bros; |
| 262 | + var caS = GameConfig.caS; |
| 263 | + cc.director.loadScene(launchScene, null, |
| 264 | + function () { |
| 265 | + |
| 266 | + adCompleteFlag = false; |
| 267 | + |
| 268 | + if (Bros) { |
| 269 | + // show canvas |
| 270 | + var canvas = document.getElementById('GameCanvas'); |
| 271 | + canvas.style.visibility = ''; |
| 272 | + var div = document.getElementById('GameDiv'); |
| 273 | + if (div) { |
| 274 | + div.style.backgroundImage = ''; |
| 275 | + } |
| 276 | + } |
| 277 | + cc.loader.onProgress = null; |
| 278 | + console.log('Success to load scene1Main: ' + launchScene); |
| 279 | + |
| 280 | + |
| 281 | + |
| 282 | + |
| 283 | + |
| 284 | + } |
| 285 | + ); |
| 286 | + |
| 287 | + |
| 288 | +} |
| 289 | + |
| 290 | + |
| 291 | + |
0 commit comments