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