093134bc-0976-4253-8969-b43c10b89220.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. "use strict";
  2. cc._RF.push(module, '09313S8CXZCU4lptDwQuJIg', 'setMap');
  3. // scripts/Game/setMap.ts
  4. "use strict";
  5. var __extends = (this && this.__extends) || (function () {
  6. var extendStatics = function (d, b) {
  7. extendStatics = Object.setPrototypeOf ||
  8. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  9. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  10. return extendStatics(d, b);
  11. };
  12. return function (d, b) {
  13. extendStatics(d, b);
  14. function __() { this.constructor = d; }
  15. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  16. };
  17. })();
  18. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  19. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  20. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  21. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  22. return c > 3 && r && Object.defineProperty(target, key, r), r;
  23. };
  24. Object.defineProperty(exports, "__esModule", { value: true });
  25. var CocosZ_1 = require("../Framework/CocosZ");
  26. var gameMgr_1 = require("./gameMgr");
  27. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  28. var setMap = /** @class */ (function (_super) {
  29. __extends(setMap, _super);
  30. function setMap() {
  31. var _this = _super !== null && _super.apply(this, arguments) || this;
  32. _this.dmmArr = [];
  33. _this.dikuai = null;
  34. _this.time = -1;
  35. _this.mainCameraPos = cc.Vec2.ZERO;
  36. _this.distanceX = 2500;
  37. _this.distanceY = 1500;
  38. return _this;
  39. }
  40. setMap.prototype.onLoad = function () {
  41. gameMgr_1.gameMgr.setMapTs = this;
  42. // 躲猫猫图片
  43. gameMgr_1.gameMgr.dmmArr = this.dmmArr;
  44. // 地块
  45. this.dikuai = this.node.getChildByName("dikuai");
  46. if (this.dikuai) {
  47. this.dikuai.zIndex = cc.macro.MIN_ZINDEX;
  48. }
  49. // 获取坐标
  50. if ([1, 2, 4].includes(CocosZ_1.cocosz.gameMode) && this.node.getChildByName("point")) {
  51. var point = this.node.getChildByName("point");
  52. for (var i = 0; i < point.childrenCount; i++) {
  53. gameMgr_1.gameMgr.posList[i] = i;
  54. }
  55. }
  56. };
  57. setMap.prototype.onDestroy = function () {
  58. gameMgr_1.gameMgr.setMapTs = null;
  59. ;
  60. };
  61. setMap.prototype.start = function () {
  62. for (var i = 0; i < this.node.children.length; i++) {
  63. // 初始zindex
  64. var child = this.node.children[i];
  65. }
  66. };
  67. setMap.prototype.lateUpdate = function () {
  68. if (CocosZ_1.cocosz.isPause || gameMgr_1.gameMgr.isWin || gameMgr_1.gameMgr.isFail)
  69. return;
  70. if (this.time++ % 30 == 0) {
  71. this.checkAllNode();
  72. }
  73. };
  74. setMap.prototype.checkAllNode = function () {
  75. if (gameMgr_1.gameMgr && gameMgr_1.gameMgr.mainCamereRootNode) {
  76. this.mainCameraPos = gameMgr_1.gameMgr.mainCamereRootNode.getPosition();
  77. this.distanceX = cc.winSize.width / 2 / gameMgr_1.gameMgr.mainCamera.zoomRatio + 500;
  78. this.distanceY = cc.winSize.height / 2 / gameMgr_1.gameMgr.mainCamera.zoomRatio + 500;
  79. }
  80. // 地图节点
  81. var excludeArr = ["guide", "guidePath", "player", "colllider", "dikuai", "point", "itemPoint", "tree", "tipLayer", "jingyanLayer", "posLayer"];
  82. for (var i = 0; i < this.node.childrenCount; i++) {
  83. var child = this.node.children[i];
  84. if (excludeArr.includes(child.name) == false) {
  85. this.checkNode(child);
  86. }
  87. }
  88. // 地图地块
  89. var dikuai = this.node.getChildByName("dikuai");
  90. if (dikuai) {
  91. for (var i = 0; i < dikuai.childrenCount; i++) {
  92. var child = dikuai.children[i];
  93. this.checkNode(child);
  94. }
  95. }
  96. };
  97. setMap.prototype.checkNode = function (n, isRefresh) {
  98. if (isRefresh === void 0) { isRefresh = false; }
  99. if (isRefresh) {
  100. if (gameMgr_1.gameMgr && gameMgr_1.gameMgr.mainCamereRootNode) {
  101. this.mainCameraPos = gameMgr_1.gameMgr.mainCamereRootNode.getPosition();
  102. this.distanceX = cc.winSize.width / 2 / gameMgr_1.gameMgr.mainCamera.zoomRatio + 500;
  103. this.distanceY = cc.winSize.height / 2 / gameMgr_1.gameMgr.mainCamera.zoomRatio + 500;
  104. }
  105. }
  106. if (n && n.isValid && n.activeInHierarchy) {
  107. if (n.parent.name == this.node.name || n.parent.name == "dikuai") {
  108. if (n.opacity == 0 || n.opacity == 255) {
  109. if (((n.x + n.width * Math.abs(n.scaleX) / 2) < (this.mainCameraPos.x - this.distanceX)) || ((n.x - n.width * Math.abs(n.scaleX) / 2) > (this.mainCameraPos.x + this.distanceX) ||
  110. (n.y + n.height * Math.abs(n.scaleY) / 2) < (this.mainCameraPos.y - this.distanceY)) || ((n.y - n.height * Math.abs(n.scaleY) / 2) > (this.mainCameraPos.y + this.distanceY))) {
  111. n.opacity = 0;
  112. return false;
  113. }
  114. else {
  115. n.opacity = 255;
  116. return true;
  117. }
  118. }
  119. }
  120. }
  121. };
  122. // 释放资源节点
  123. setMap.prototype.release = function (call) {
  124. var _this = this;
  125. // 删除dikaui子节点
  126. if (this.dikuai && this.dikuai.isValid && this.dikuai.childrenCount) {
  127. for (var i = 0; i < 2; i++) {
  128. var child = this.dikuai.children[i];
  129. if (child && child.isValid) {
  130. child.destroy();
  131. }
  132. }
  133. setTimeout(function () { _this.release(call); });
  134. }
  135. // 删除普通节点
  136. else if (this.node.childrenCount) {
  137. for (var i = 0; i < 10; i++) {
  138. var child = this.node.children[i];
  139. if (child && child.isValid) {
  140. child.destroy();
  141. }
  142. }
  143. setTimeout(function () { _this.release(call); });
  144. }
  145. // 结束后回调
  146. else {
  147. call && call();
  148. }
  149. };
  150. __decorate([
  151. property([cc.SpriteFrame])
  152. ], setMap.prototype, "dmmArr", void 0);
  153. setMap = __decorate([
  154. ccclass
  155. ], setMap);
  156. return setMap;
  157. }(cc.Component));
  158. exports.default = setMap;
  159. cc._RF.pop();