Loading.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { _decorator, Component, director, Node, resources, SceneAsset, Sprite } from 'cc';
  2. import { DEBUG } from 'cc/env';
  3. const { ccclass, property } = _decorator;
  4. @ccclass('Loading')
  5. export class Loading extends Component {
  6. @property(Node)
  7. RankNode: Node = null;
  8. @property(Node)
  9. StartNode: Node = null;
  10. @property(Node)
  11. SliderNode: Node = null;
  12. protected onLoad(): void {
  13. this.init()
  14. this.Startloading()
  15. }
  16. init() {
  17. this.RankNode.active = false;
  18. this.StartNode.active = false;
  19. this.SliderNode.active = true;
  20. this.SliderNode.getComponentInChildren(Sprite).fillRange = 0;
  21. }
  22. Startloading() {
  23. resources.preloadScene('Game', (finished: number, total: number) => {
  24. if ((finished / total) > this.SliderNode.getComponentInChildren(Sprite).fillRange) {
  25. this.SliderNode.getComponentInChildren(Sprite).fillRange = finished / total;
  26. }
  27. }
  28. , (err) => {
  29. if (err) {
  30. console.error(err);
  31. return;
  32. }
  33. this.OverLoading()
  34. console.log('预加载场景成功');
  35. if (DEBUG) {
  36. // this.ClickGame()
  37. }
  38. })
  39. }
  40. OverLoading() {
  41. this.SliderNode.active = false;
  42. this.StartNode.active = true;
  43. this.RankNode.active = true;
  44. }
  45. ClickGame() {
  46. director.loadScene('Game', (err) => {
  47. if (err) {
  48. console.error(err);
  49. return;
  50. }
  51. console.log('加载场景成功');
  52. })
  53. }
  54. ClickRank() {
  55. console.log('点击排行榜');
  56. }
  57. }