pageManager.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * @author heyuchang
  3. * @file 通用页面控制器和适配
  4. */
  5. var AC = require('GameAct')
  6. cc.Class({
  7. extends: cc.Component,
  8. properties: {
  9. status: 0, //页面状态
  10. pages: [cc.Node],
  11. },
  12. // 0 开始游戏页面
  13. // 1 游戏页面
  14. // 2 UI页面
  15. // 3 过关页面
  16. // 4 失败页面
  17. // 5 复活页面
  18. // 6 排行榜页面
  19. start() {
  20. this.lateStart()
  21. },
  22. lateStart() {
  23. this.width = cc.winSize.width
  24. window.width = this.width
  25. this.height = cc.winSize.height
  26. window.height = this.height
  27. // 存为全局变量
  28. this.adoptCanvas()
  29. },
  30. // 适配解决方案
  31. adoptCanvas() {
  32. let canvas = cc.director.getScene().getChildByName('Canvas').getComponent(cc.Canvas)
  33. // 设计分辨率比
  34. let rateR = canvas.designResolution.height / canvas.designResolution.width;
  35. // 显示分辨率比
  36. let rateV = this.height / this.width;
  37. if (rateV > rateR) {
  38. canvas.fitHeight = false;
  39. canvas.fitWidth = true;
  40. } else {
  41. canvas.fitHeight = true;
  42. canvas.fitWidth = false;
  43. }
  44. },
  45. onOpenPage(num, callFun) {
  46. this.closeAllPages()
  47. this.pages[num].active = true
  48. // if (callFun) {
  49. // this.callFun();
  50. // }
  51. },
  52. addPage(num, callFun) {
  53. this.pages[num].scale = 0.5
  54. this.pages[num].active = true
  55. this.pages[num].runAction(AC.popOut(0.5))
  56. // if (callFun) {
  57. // this.callFun();
  58. // }
  59. },
  60. removePage(num, callFun) {
  61. this.pages[num].runAction(cc.sequence(AC.popIn(0.5),cc.callFunc(()=>{
  62. this.pages[num].active = false
  63. },this)))
  64. // if (callFun) {
  65. // this.callFun();
  66. // }
  67. },
  68. onButtonOpenPage(event, cust) {
  69. this.onOpenPage(cust);
  70. },
  71. onButtonAddPage(event, cust) {
  72. this.addPage(cust);
  73. },
  74. onButtonRemovePage(event, cust) {
  75. this.removePage(cust);
  76. },
  77. closeAllPages() {
  78. this.pages.forEach(element => {
  79. element.active = false
  80. });
  81. },
  82. });