最近公司需要將之前的項目發個版本到頭條小程序,這個項目是5.2.33版本的,然後白鷺支持頭條小程序的版本需要是5.3.8,所以需要把版本升級到5.3.8
1、首先打開項目,我用的ide還是egret wing,在終端上輸入egret upgrade --egretversion 後面再加上版本號,升級的前提需要先下載要升級到的引擎。
點擊回車就自動升級,由於版本更替,可能會出現之前項目有些地方報錯,這是因爲白鷺新的api不支持了,目前我遇到的就是dragonBones這個類庫和舊的版本不太一樣,有的方法已經不用了,
這裏大家根據自己的項目,報錯找對應解決辦法,情況各不一樣。
2、升級完成之後,保證項目可以正常運行,我們就可以試着去Egret Launcher上發佈頭條小程序了,找到字節跳動小遊戲,需要先下載小遊戲工具包,根據提示操作就可以了。
接着會出現上面的窗口,這裏我們做測試版本的話,AppID隨便填就可以了,項目名稱也是一樣,填寫完成之後,先點擊發布。
如果是升級的項目百分百會出現這個錯誤提示
因爲項目是升級過來的,升級過程中只是換了egret api和發佈平臺對應的接口類,所以在scripts文件夾中沒有plugins這個文件夾,打包的時候找不到,
要解決這個問題,需要用升級到的引擎,(比如我的是5.3.8)創建一個新項目,再把新項目裏的plugins文件放到要打包的項目中。
這時候我們的項目就可以發佈了
這裏我們選擇Release,發佈之後我們用 字節跳動開發者工具打開 ttgame的那個文件。一般情況下
選擇編譯,就可以編譯你的項目了。
3、上面的步驟是可以在頭條上玩了,光玩還不夠,咱們的目的不是這,還是需要恰飯的。
下面就要對接一下字節跳動的廣告了,字節跳動小遊戲上有三種廣告,分別爲banner 激勵視頻 插屏這三種,需要接入前提是申請了流量主,有了流量主就有這三個廣告接入id
這裏接過微信小遊戲的同學都知道。
這個放上 字節跳動小遊戲開發能力 字節跳動小遊戲api 鏈接
最好寫一個字節跳動管理類,在類裏面定義和調動頭條的api方法
例如打開插屏廣告
//插屏廣告 public OpenScreen(id: any) {const screenAd = tt.createInterstitialAd({ adUnitId: id }); screenAd.onLoad(() => { console.log('插屏 廣告加載成功'); screenAd.show().catch((err) => { console.error(err); }) .catch((err) => { console.log("廣告組件出現問題", err); }); }); screenAd.onError(err => { console.log('插屏 廣告加載失敗' + err); }); screenAd.onClose(res => { console.log('插屏 廣告關閉') }); }
打開banner廣告
public OpenBanner(id: string, _left = 0, _top = 1200, _width = 350, open: Function = null) { let systemData = tt.getSystemInfoSync(); if (!systemData) { return };
_left = (systemData['windowWidth'] - 350) / 2; _top = systemData['windowHeight'] - 120; var aplha = 1;//document.documentElement.clientWidth / 720; const bannerAd = tt.createBannerAd({ adUnitId: id,//banner id style: { left: _left,//左邊位置 top: _top,//上邊往下位置 width: _width * aplha,//寬度 height: 50 } }); bannerAd.onLoad(() => { console.log('banner 廣告加載成功') bannerAd.style.width = _width * aplha;//隨時設置banner寬 bannerAd.show(); if (open != null) open(); }) bannerAd.onError(err => { console.log('banner 廣告加載失敗' + err); }); if (bannerAd != null) this.BannerArr.push(bannerAd); this.CurBanner = bannerAd; }
//關閉當前Banner public CloseCurBanner() { console.error("關閉當前banner"); for (var i in this.BannerArr) { if (this.BannerArr[i] != null) this.BannerArr[i].destroy(); } } //清空Banner public ClearBanner() { console.error("關閉所有banner了"); for (var i in this.BannerArr) { if (this.BannerArr[i] != null) this.BannerArr[i].destroy(); } }
打開激勵廣告
public safeclose: Function = null; public unsafeclose: Function = null; public scope: any = null; //打開激勵廣告 public OpenAD(id: string, safeclose: Function = null, unsafeclose: Function = null, scope = null) { if (DEBUG) { if (safeclose) { safeclose.apply(scope); } return; }const videoAd = tt.createRewardedVideoAd({ adUnitId: id }); this.safeclose = safeclose; this.unsafeclose = unsafeclose; this.scope = scope; videoAd.show().catch(() => { // 失敗重試 videoAd.load().then(() => videoAd.show()) .catch(err => { console.log('激勵視頻 廣告顯示失敗') }) }); videoAd.onError(err => { console.error("打開廣告失敗" + err); }); videoAd.onClose(res => { if (res && res.isEnded) { // 正常播放結束,可以下發遊戲獎勵 console.error("正常關閉廣告了"); if (this.safeclose != null) this.safeclose.apply(this.scope); videoAd.offClose(); } else { // 播放中途退出,不下發遊戲獎勵 console.error("播放中途關閉廣告了"); if (this.unsafeclose != null) this.unsafeclose.apply(this.scope); videoAd.offClose(); } }); }
4、想要通過頭條的審覈,還需要了解必須接的功能
第一個內容安全檢測,這個對於沒有輸入功能的遊戲,可以不接,第二個,算是首要的功能,必須要接,第三個,這個一般來說小遊戲沒有登陸功能的話,也可以不接
對於分享功能可以參考官方api文檔。
public _videoPath: any = null; public recorder = null //開始錄屏 public startRecordScreen(time: number = 60) { if (!this.recorder) this.recorder = tt.getGameRecorderManager(); this.recorder.start({ duration: time || 15, }); this.recorder.onStart(res => { console.log("開始錄屏"); }); this.recorder.onPause(res => { console.log("錄屏暫停"); }); this.recorder.onResume(res => { console.log("繼續錄屏"); }); this.recorder.onStop(res => { console.log("錄屏結束" + res.videoPath); this._videoPath = res.videoPath; }); } //錄屏暫停 public OnPause(){ if (!this.recorder) return; this.recorder.pause(); } //繼續錄屏 public OnResume(){ if (!this.recorder) return; this.recorder.resume(); } //結束錄屏 public stopRecordScreen() { if (!this.recorder) return; this.recorder.stop(); } //分享視頻 public shareVideoMsg() { if (!PlayerData.m_bIsTouTiao) return; if (!this._videoPath)return; tt.shareAppMessage({ channel: 'video', title: '大亂鬥', desc: '', query: '', imageUrl: '', templateId: '', extra: { videoPath: this._videoPath, // 可用錄屏得到的視頻地址 videoTopics: ['大亂鬥', '抖音小遊戲'], hashtag_list: ['大亂鬥', '抖音小遊戲'] }, success() { TipMsgCenter.getInstance().PopTipMsg("分享成功", 0); }, fail(e) { TipMsgCenter.getInstance().PopTipMsg("分享失敗", 0); } }) }
遊戲的審覈標準就是看看有沒有接錄屏功能,並且錄屏功能要放在顯眼的地方,避免打回頭重新審覈,這個要誇一下,頭條的審覈速度是真的快,上午剛提交審覈,過一會兒就好了,當然有時肯定人家也忙,2天之內,一定會進行審覈的。