TiledMapUnit.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. var Constants = require('Constants');
  2. var tiledMapUnit = cc.Class({
  3. name: "tiledMapUnit",
  4. properties: () => ({
  5. //获取id
  6. getBuildingID: {
  7. get: function () {
  8. return this._id;
  9. }
  10. },
  11. //占位的起始点,左下角的tiled
  12. getIsItOccupyPosition: {
  13. get: function () {
  14. return this._isItOccupyPosition;
  15. }
  16. },
  17. // isItOccupyPosition: [cc.Boolean],
  18. getTiledPosition: {
  19. get: function () {
  20. return this._tiledStartPosition;
  21. }
  22. },
  23. //占位的区域,比如是3*3 ,起点往后各占3格
  24. getOccupyingArea: {
  25. get: function () {
  26. return cc.v2(this._row, this._column);
  27. }
  28. },
  29. //对象的siblingIndex
  30. getSiblingIndex: {
  31. get: function () {
  32. return this._getSiblingIndex;
  33. }
  34. },
  35. //对象的ZIndex
  36. getZIndex: {
  37. get: function () {
  38. return this._ZIndex;
  39. }
  40. },
  41. //约定的index 的数组
  42. getIndexArray: {
  43. get: function () {
  44. return this._tiledIndexArray;
  45. }
  46. },
  47. //目标的buildingsInfo脚本
  48. getBuildingsInfo: {
  49. get: function () {
  50. return this._buildingsInfo;
  51. }
  52. }
  53. }),
  54. //记录对象的id,唯一的
  55. //只设置一次
  56. onSetBuildingID(id) {
  57. this._id = id;
  58. },
  59. //设置对象的siblingIndex
  60. onSetSiblingIndex(_siblingIndex) {
  61. this._getSiblingIndex = _siblingIndex;
  62. },
  63. //根据约定值取出渲染的index
  64. onGetSblingIndexFromIndex(_stargetIndex) {
  65. if (!this._tiledIndexArray)
  66. return false;
  67. let length = this._tiledIndexArray.length;
  68. for (let i = 0; i < length; i++) {
  69. if (targetIndex === this._tiledIndexArray[i])
  70. return this._getSiblingIndex;
  71. }
  72. return false;
  73. },
  74. //设置对象的ZIndex
  75. onSetZIndex(_ZIndex) {
  76. this._ZIndex = _ZIndex;
  77. },
  78. //根据约定值取出渲染的ZIndex
  79. onGetZIndexFromIndex(_stargetIndex) {
  80. if (!this._tiledIndexArray)
  81. return false;
  82. let length = this._tiledIndexArray.length;
  83. for (let i = 0; i < length; i++) {
  84. if (targetIndex === this._tiledIndexArray[i])
  85. return this._ZIndex;
  86. }
  87. return false;
  88. },
  89. //记录初始tile位置
  90. onSetStartTiledPos(tiledPos) {
  91. this._tiledStartPosition = tiledPos;
  92. },
  93. //Init Occupy State
  94. onSetOccupyState(value) {
  95. this._isItOccupyPosition = value;
  96. },
  97. //左边记为列 右边为行
  98. onSetOccupyingArea(x, y) {
  99. this._row = x;
  100. this._column = y;
  101. },
  102. //记录约定数组
  103. onSetIndexArray(index) {
  104. this._tiledIndexArray = index;
  105. },
  106. //记录目标的buildingsInfo脚本
  107. onSetBuildingsInfo(buildingsInfo) {
  108. this._buildingsInfo = buildingsInfo;
  109. },
  110. //约定的index是否存在这里
  111. onIndexExistInThis(targetIndex) {
  112. if (!this._tiledIndexArray)
  113. return false;
  114. let length = this._tiledIndexArray.length;
  115. for (let i = 0; i < length; i++) {
  116. if (targetIndex === this._tiledIndexArray[i])
  117. return true;
  118. }
  119. return false;
  120. }
  121. });
  122. module.exports = tiledMapUnit;