LoadingRes.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. var Global = require("Global");
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. },
  6. // LIFE-CYCLE CALLBACKS:
  7. onLoad () {},
  8. showGoGameScene: function(arrRes, funCall) {
  9. this.node.active = true;
  10. this.updateProgress(0);
  11. var self = this;
  12. cc.resources.load(arrRes, function (completedCount, totalCount, item) {
  13. self.updateProgress((completedCount / totalCount));
  14. },
  15. function (err, assets) {
  16. if (funCall) {
  17. funCall();
  18. }
  19. });
  20. },
  21. loadingDir: function (strPath, funCall) {
  22. var self = this;
  23. cc.resources.loadDir(strPath, function (completedCount, totalCount, item) {
  24. if (totalCount > 0) {
  25. var percent = completedCount / totalCount;
  26. self.updateProgress(percent);
  27. }
  28. },
  29. function (err, prefab) {
  30. if (funCall) {
  31. funCall();
  32. }
  33. });
  34. },
  35. showBackHomeScene: function(startFun, endFun) {
  36. this.node.active = true;
  37. this.updateProgress(0);
  38. var self = this;
  39. this.scheduleOnce(function() {
  40. if (startFun) {
  41. startFun();
  42. }
  43. self.loadingDir("GamePrefabs/homescence", function () {
  44. if (endFun) {
  45. endFun();
  46. }
  47. cc.director.loadScene("hallscence");
  48. });
  49. }, 0.1);
  50. },
  51. updateProgress: function(percent) {
  52. this.node.getChildByName("Progress").width = 800 * percent;
  53. },
  54. hide: function() {
  55. this.node.active = false;
  56. },
  57. });