import GameMgr, { Sound } from "../GameMgr"; import GameConfig from "../GameConfig"; const {ccclass, property} = cc._decorator; @ccclass export default class MainPage extends cc.Component { static instance: MainPage; onLoad() { MainPage.instance = this; GameMgr.instance.playMusic(Sound.bg_music); cc.assetManager.loadRemote(GameConfig.remote_res + "songs.json?v=" + Date.now(), (err, res: cc.JsonAsset) => { if (!err) { GameConfig.song_infos = res.json; } this.node.getChildByName('cover_flow').active = true; }); } startGame(song_id: number) { GameMgr.instance.song_id = song_id; document.getElementById("splash").style.display = "block"; let completeCount = 0; this.schedule(() => { completeCount++; document.getElementById("loading-text-div").innerHTML = "音乐加载中(" + completeCount + "%)"; }, 0.08, 98, 0); let audio_url = GameConfig.remote_res + song_id + ".mp3?v=" + GameConfig.song_res_version; let json_url = GameConfig.remote_res + song_id + ".json?v=" + GameConfig.song_res_version; cc.loader.load([audio_url, json_url], (err) => { if (!err) { this.unscheduleAllCallbacks(); document.getElementById("loading-text-div").innerHTML = "音乐加载中(100%)"; this.scheduleOnce(() => { document.getElementById("splash").style.display = "none"; GameMgr.instance.song = cc.loader.getRes(audio_url); GameMgr.instance.beats = cc.loader.getRes(json_url); GameMgr.instance.addPage(GameMgr.instance.game_page); cc.audioEngine.stopMusic(); this.node.destroy(); }, 0.3); } }); GameMgr.instance.playEffect(Sound.button_effect); } }