|
import PromoFetchFB from "./PromoFetchFB";
|
|
const { ccclass, property } = cc._decorator;
|
|
/**
|
* 推广自家游戏
|
*/
|
@ccclass
|
export class PromoShowFB extends cc.Component {
|
|
@property(cc.Button)
|
promoButton: cc.Button = null;
|
@property(cc.Sprite)
|
promoSprite: cc.Sprite = null;
|
|
promoIndex: number = -1;
|
onLoad() {
|
this.promoButton.node.active = false;
|
}
|
|
onEnable() {
|
this.schedule(this.changePromoImage, 10, cc.macro.REPEAT_FOREVER, 1);//10秒check一次
|
}
|
|
onDisable() {
|
this.unschedule(this.changePromoImage);
|
}
|
|
startPromoButtonAction() {
|
this.promoButton.node.stopAllActions();
|
this.promoButton.node.runAction(
|
cc.repeatForever(
|
cc.sequence(
|
cc.scaleTo(0.5, 1),
|
cc.scaleTo(0.3, 0.95)
|
)
|
)
|
);
|
}
|
|
changePromoImage() {
|
if (PromoFetchFB.ins && PromoFetchFB.ins.PromoSpriteFrames.length > 0) {
|
if (!this.promoButton.node.active) {
|
this.promoButton.node.active = true;
|
this.startPromoButtonAction();
|
}
|
|
this.promoIndex++;
|
if (this.promoIndex >= PromoFetchFB.ins.PromoSpriteFrames.length) {
|
this.promoIndex = 0;
|
}
|
|
this.promoSprite.spriteFrame = PromoFetchFB.ins.PromoSpriteFrames[this.promoIndex].spriteFrame;
|
} else {
|
this.promoButton.node.active = false;
|
}
|
}
|
|
|
onClickPromo() {
|
let appid = PromoFetchFB.ins.PromoSpriteFrames[this.promoIndex].appid;
|
|
if (typeof FBInstant !== 'undefined') {
|
FBInstant.switchGameAsync(appid);
|
}
|
else {
|
cc.log("点击跳转 -> " + appid);
|
}
|
}
|
|
// update (dt) {}
|
}
|