CCTMXObjectGroup.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /****************************************************************************
  2. Copyright (c) 2008-2010 Ricardo Quesada
  3. Copyright (c) 2011-2012 cocos2d-x.org
  4. Copyright (c) 2013-2014 Chukong Technologies Inc.
  5. http://www.cocos2d-x.org
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12. The above copyright notice and this permission notice shall be included in
  13. all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. THE SOFTWARE.
  21. ****************************************************************************/
  22. /**
  23. * cc.TMXObjectGroup represents the TMX object group.
  24. * @class
  25. * @extends cc.Class
  26. *
  27. * @property {Array} properties - Properties from the group. They can be added using tilemap editors
  28. * @property {String} groupName - Name of the group
  29. */
  30. cc.TMXObjectGroup = cc.Class.extend(/** @lends cc.TMXObjectGroup# */{
  31. properties: null,
  32. groupName: "",
  33. _positionOffset: null,
  34. _objects: null,
  35. /**
  36. * <p>The cc.TMXObjectGroup's constructor. <br/>
  37. * This function will automatically be invoked when you create a node using new construction: "var node = new cc.TMXObjectGroup()".<br/>
  38. * Override it to extend its behavior, remember to call "this._super()" in the extended "ctor" function.</p>
  39. */
  40. ctor:function () {
  41. this.groupName = "";
  42. this._positionOffset = cc.p(0,0);
  43. this.properties = [];
  44. this._objects = [];
  45. },
  46. /**
  47. * Offset position of child objects
  48. * @return {cc.Point}
  49. */
  50. getPositionOffset:function () {
  51. return cc.p(this._positionOffset);
  52. },
  53. /**
  54. * Offset position of child objects
  55. * @param {cc.Point} offset
  56. */
  57. setPositionOffset:function (offset) {
  58. this._positionOffset.x = offset.x;
  59. this._positionOffset.y = offset.y;
  60. },
  61. /**
  62. * List of properties stored in a dictionary
  63. * @return {Array}
  64. */
  65. getProperties:function () {
  66. return this.properties;
  67. },
  68. /**
  69. * List of properties stored in a dictionary
  70. * @param {object} Var
  71. */
  72. setProperties:function (Var) {
  73. this.properties.push(Var);
  74. },
  75. /**
  76. * Gets the Group name.
  77. * @return {String}
  78. */
  79. getGroupName:function () {
  80. return this.groupName.toString();
  81. },
  82. /**
  83. * Set the Group name
  84. * @param {String} groupName
  85. */
  86. setGroupName:function (groupName) {
  87. this.groupName = groupName;
  88. },
  89. /**
  90. * Return the value for the specific property name
  91. * @param {String} propertyName
  92. * @return {object}
  93. */
  94. propertyNamed:function (propertyName) {
  95. return this.properties[propertyName];
  96. },
  97. /**
  98. * <p>Return the dictionary for the specific object name. <br />
  99. * It will return the 1st object found on the array for the given name.</p>
  100. * @param {String} objectName
  101. * @return {object|Null}
  102. */
  103. objectNamed:function (objectName) {
  104. if (this._objects && this._objects.length > 0) {
  105. var locObjects = this._objects;
  106. for (var i = 0, len = locObjects.length; i < len; i++) {
  107. var name = locObjects[i]["name"];
  108. if (name && name == objectName)
  109. return locObjects[i];
  110. }
  111. }
  112. // object not found
  113. return null;
  114. },
  115. /**
  116. * Gets the objects.
  117. * @return {Array}
  118. */
  119. getObjects:function () {
  120. return this._objects;
  121. },
  122. /**
  123. * Set the objects.
  124. * @param {object} objects
  125. */
  126. setObjects:function (objects) {
  127. this._objects.push(objects);
  128. }
  129. });