Loading.ts 1.6 KB

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