sweet/assets/scriptes/banner.js
2020-08-07 09:55:56 +08:00

98 lines
2.2 KiB
JavaScript

// Learn cc.Class:
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
// - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
// - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
// - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
var Global = require('global');
cc.Class({
extends: cc.Component,
properties: {
adName: '',
adId: '',
adIdQQ: '',
adTop: -1,
// 当有这些节点时, 不显示banner
noADChilds: [cc.Node],
isAuto: true,
isSimple: false
},
// LIFE-CYCLE CALLBACKS:
onLoad() {
// this.adId = Global.getBannnerId();
if (cc.jc.channelID === cc.jc.channel.QQ_MINI) {
this.adId = this.adIdQQ;
}
this.ad_name = this.adName;
if (!this.ad_name) {
this.ad_name = this.adId;
}
if (this.adId && this.isAuto && !this.isSimple) {
cc.jc.ADBanner_init(this.adId, this.ad_name);
}
},
// start () {},
// update (dt) {},
onEnable() {
if (this.isAuto) {
this.scheduleOnce(() => {
this.ADShow();
}, 1);
}
},
onDisable() {
this.ADHide();
},
canShow() {
if (!this.ad_name) {
return false;
}
let obj = this.noADChilds.forEach(element => {
return element.active == true;
});
return !obj;
},
ADShow() {
if (this.canShow()) {
if (this.isSimple) {
this.adobj = cc.jc.ad.simpleBannerADShow(this.adId, 120, this.adTop);
} else {
if (!this.isAuto) {
cc.jc.ADBanner_init(this.adId, this.ad_name);
}
cc.jc.ADBanner_Show(this.ad_name);
}
this.adshow = true;
}
},
ADHide() {
if (this.adshow) {
if (this.isSimple) {
this.adobj && this.adobj.hide && this.adobj.hide();
} else {
cc.jc.ADBanner_Hide(this.ad_name);
}
this.adshow = false;
}
}
});