|
const { ccclass, property } = cc._decorator;
|
|
/**
|
* 从服务器获取推荐数据
|
*/
|
@ccclass
|
export default class PromoFetchFB extends cc.Component {
|
private static _ins: PromoFetchFB = null;
|
private static readonly PROMO_URL = "https://www.qingchao.org/promos/bb.json?" + Date.now();
|
private isLoaded: boolean = false;
|
private promoSpriteFrames = [];//
|
|
public static get ins(): PromoFetchFB {
|
return PromoFetchFB._ins;
|
}
|
|
public get PromoSpriteFrames(): any[] {
|
return this.promoSpriteFrames;
|
}
|
|
onLoad() {
|
PromoFetchFB._ins = this;
|
cc.game.addPersistRootNode(this.node);
|
}
|
|
onEnable() {
|
if (cc.sys.os != cc.sys.OS_IOS && cc.sys.os != cc.sys.OS_OSX) {
|
if (!this.isLoaded) {
|
this.isLoaded = true;
|
this.loadJson();
|
}
|
}
|
}
|
|
loadJson() {
|
cc.loader.load(PromoFetchFB.PROMO_URL, (err, data) => {
|
if (err) {
|
cc.log('err = ', err);
|
return;
|
}
|
|
// let promoArray = JSON.parse(data);
|
console.log('load promo data = ', data);
|
if (data) {//加载纹理图
|
let keys = Object.keys(data);
|
keys.forEach((appid) => {
|
cc.loader.load({ url: data[appid], type: 'png' }, (err, texture) => {
|
if (texture) {
|
this.promoSpriteFrames.push({
|
appid: appid,
|
spriteFrame: new cc.SpriteFrame(texture)
|
});
|
}
|
});
|
});
|
}
|
})
|
}
|
}
|