MainPage.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import GameMgr, { Sound } from "../GameMgr";
  2. import GameConfig from "../GameConfig";
  3. const {ccclass, property} = cc._decorator;
  4. @ccclass
  5. export default class MainPage extends cc.Component {
  6. static instance: MainPage;
  7. onLoad() {
  8. MainPage.instance = this;
  9. GameMgr.instance.playMusic(Sound.bg_music);
  10. cc.assetManager.loadRemote(GameConfig.remote_res + "songs.json?v=" + Date.now(), (err, res: cc.JsonAsset) => {
  11. if (!err) {
  12. GameConfig.song_infos = res.json;
  13. }
  14. this.node.getChildByName('cover_flow').active = true;
  15. });
  16. }
  17. startGame(song_id: number) {
  18. GameMgr.instance.song_id = song_id;
  19. document.getElementById("splash").style.display = "block";
  20. let completeCount = 0;
  21. this.schedule(() => {
  22. completeCount++;
  23. document.getElementById("loading-text-div").innerHTML = "音乐加载中(" + completeCount + "%)";
  24. }, 0.08, 98, 0);
  25. let audio_url = GameConfig.remote_res + song_id + ".mp3?v=" + GameConfig.song_res_version;
  26. let json_url = GameConfig.remote_res + song_id + ".json?v=" + GameConfig.song_res_version;
  27. cc.loader.load([audio_url, json_url], (err) => {
  28. if (!err) {
  29. this.unscheduleAllCallbacks();
  30. document.getElementById("loading-text-div").innerHTML = "音乐加载中(100%)";
  31. this.scheduleOnce(() => {
  32. document.getElementById("splash").style.display = "none";
  33. GameMgr.instance.song = cc.loader.getRes(audio_url);
  34. GameMgr.instance.beats = cc.loader.getRes(json_url);
  35. GameMgr.instance.addPage(GameMgr.instance.game_page);
  36. cc.audioEngine.stopMusic();
  37. this.node.destroy();
  38. }, 0.3);
  39. }
  40. });
  41. GameMgr.instance.playEffect(Sound.button_effect);
  42. }
  43. }