CCTMXObjectGroup.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /****************************************************************************
  2. Copyright (c) 2010-2012 cocos2d-x.org
  3. Copyright (c) 2008-2010 Ricardo Quesada
  4. Copyright (c) 2011 Zynga 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. cc.TMXObjectGroup = cc.Class.extend(/** @lends cc.TMXObjectGroup# */{
  28. //name of the group
  29. _groupName:null,
  30. _positionOffset:null,
  31. _properties:null,
  32. _objects:null,
  33. /**
  34. * Constructor
  35. */
  36. ctor:function () {
  37. this._groupName = "";
  38. this._positionOffset = cc.p(0,0);
  39. this._properties = [];
  40. this._objects = [];
  41. },
  42. /**
  43. * Offset position of child objects
  44. * @return {cc.Point}
  45. */
  46. getPositionOffset:function () {
  47. return cc.p(this._positionOffset);
  48. },
  49. /**
  50. * @param {cc.Point} Var
  51. */
  52. setPositionOffset:function (Var) {
  53. this._positionOffset.x = Var.x;
  54. this._positionOffset.y = Var.y;
  55. },
  56. /**
  57. * List of properties stored in a dictionary
  58. * @return {Array}
  59. */
  60. getProperties:function () {
  61. return this._properties;
  62. },
  63. /**
  64. * @param {object} Var
  65. */
  66. setProperties:function (Var) {
  67. this._properties.push(Var);
  68. },
  69. /**
  70. * @return {String}
  71. */
  72. getGroupName:function () {
  73. return this._groupName.toString();
  74. },
  75. /**
  76. * @param {String} groupName
  77. */
  78. setGroupName:function (groupName) {
  79. this._groupName = groupName;
  80. },
  81. /**
  82. * Return the value for the specific property name
  83. * @param {String} propertyName
  84. * @return {object}
  85. */
  86. propertyNamed:function (propertyName) {
  87. return this._properties[propertyName];
  88. },
  89. /**
  90. * <p>Return the dictionary for the specific object name. <br />
  91. * It will return the 1st object found on the array for the given name.</p>
  92. * @param {String} objectName
  93. * @return {object|Null}
  94. */
  95. objectNamed:function (objectName) {
  96. if (this._objects && this._objects.length > 0) {
  97. var locObjects = this._objects;
  98. for (var i = 0, len = locObjects.length; i < len; i++) {
  99. var name = locObjects[i]["name"];
  100. if (name && name == objectName)
  101. return locObjects[i];
  102. }
  103. }
  104. // object not found
  105. return null;
  106. },
  107. /**
  108. * @return {Array}
  109. */
  110. getObjects:function () {
  111. return this._objects;
  112. },
  113. /**
  114. * @param {object} objects
  115. */
  116. setObjects:function (objects) {
  117. this._objects.push(objects);
  118. }
  119. });