123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861 |
- /****************************************************************************
- Copyright (c) 2010-2012 cocos2d-x.org
- Copyright (c) 2008-2010 Ricardo Quesada
- Copyright (c) 2011 Zynga Inc.
- http://www.cocos2d-x.org
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- ****************************************************************************/
- /**
- * @constant
- * @type Number
- */
- cc.TMX_LAYER_ATTRIB_NONE = 1 << 0;
- /**
- * @constant
- * @type Number
- */
- cc.TMX_LAYER_ATTRIB_BASE64 = 1 << 1;
- /**
- * @constant
- * @type Number
- */
- cc.TMX_LAYER_ATTRIB_GZIP = 1 << 2;
- /**
- * @constant
- * @type Number
- */
- cc.TMX_LAYER_ATTRIB_ZLIB = 1 << 3;
- /**
- * @constant
- * @type Number
- */
- cc.TMX_PROPERTY_NONE = 0;
- /**
- * @constant
- * @type Number
- */
- cc.TMX_PROPERTY_MAP = 1;
- /**
- * @constant
- * @type Number
- */
- cc.TMX_PROPERTY_LAYER = 2;
- /**
- * @constant
- * @type Number
- */
- cc.TMX_PROPERTY_OBJECTGROUP = 3;
- /**
- * @constant
- * @type Number
- */
- cc.TMX_PROPERTY_OBJECT = 4;
- /**
- * @constant
- * @type Number
- */
- cc.TMX_PROPERTY_TILE = 5;
- /**
- * @constant
- * @type Number
- */
- cc.TMX_TILE_HORIZONTAL_FLAG = 0x80000000;
- /**
- * @constant
- * @type Number
- */
- cc.TMX_TILE_VERTICAL_FLAG = 0x40000000;
- /**
- * @constant
- * @type Number
- */
- cc.TMX_TILE_DIAGONAL_FLAG = 0x20000000;
- /**
- * @constant
- * @type Number
- */
- cc.TMX_TILE_FLIPPED_ALL = (cc.TMX_TILE_HORIZONTAL_FLAG | cc.TMX_TILE_VERTICAL_FLAG | cc.TMX_TILE_DIAGONAL_FLAG) >>> 0;
- /**
- * @constant
- * @type Number
- */
- cc.TMX_TILE_FLIPPED_MASK = (~(cc.TMX_TILE_FLIPPED_ALL)) >>> 0;
- // Bits on the far end of the 32-bit global tile ID (GID's) are used for tile flags
- /**
- * <p>cc.TMXLayerInfo contains the information about the layers like: <br />
- * - Layer name<br />
- * - Layer size <br />
- * - Layer opacity at creation time (it can be modified at runtime) <br />
- * - Whether the layer is visible (if it's not visible, then the CocosNode won't be created) <br />
- * <br />
- * This information is obtained from the TMX file.</p>
- * @class
- * @extends cc.Class
- */
- cc.TMXLayerInfo = cc.Class.extend(/** @lends cc.TMXLayerInfo# */{
- _properties:null,
- name:"",
- _layerSize:null,
- _tiles:null,
- visible:null,
- _opacity:null,
- ownTiles:true,
- _minGID:100000,
- _maxGID:0,
- offset:null,
- ctor:function () {
- this._properties = [];
- this.name = "";
- this._layerSize = null;
- this._tiles = [];
- this.visible = true;
- this._opacity = 0;
- this.ownTiles = true;
- this._minGID = 100000;
- this._maxGID = 0;
- this.offset = cc.PointZero();
- },
- /**
- * @return {Array}
- */
- getProperties:function () {
- return this._properties;
- },
- /**
- * @param {object} Var
- */
- setProperties:function (Var) {
- this._properties = Var;
- }
- });
- /**
- * <p>cc.TMXTilesetInfo contains the information about the tilesets like: <br />
- * - Tileset name<br />
- * - Tileset spacing<br />
- * - Tileset margin<br />
- * - size of the tiles<br />
- * - Image used for the tiles<br />
- * - Image size<br />
- *
- * This information is obtained from the TMX file. </p>
- * @class
- * @extends cc.Class
- */
- cc.TMXTilesetInfo = cc.Class.extend(/** @lends cc.TMXTilesetInfo# */{
- /**
- * Tileset name
- */
- name:"",
- /**
- * First grid
- */
- firstGid:0,
- _tileSize:null,
- /**
- * Spacing
- */
- spacing:0,
- /**
- * Margin
- */
- margin:0,
- /**
- * Filename containing the tiles (should be sprite sheet / texture atlas)
- */
- sourceImage:"",
- /**
- * Size in pixels of the image
- */
- imageSize:null,
- ctor:function () {
- this._tileSize = cc.SizeZero();
- this.imageSize = cc.SizeZero();
- },
- /**
- * @param {Number} gid
- * @return {cc.Rect}
- */
- rectForGID:function (gid) {
- var rect = cc.RectZero();
- rect._size = this._tileSize;
- gid &= cc.TMX_TILE_FLIPPED_MASK;
- gid = gid - parseInt(this.firstGid, 10);
- var max_x = parseInt((this.imageSize.width - this.margin * 2 + this.spacing) / (this._tileSize.width + this.spacing), 10);
- rect._origin.x = parseInt((gid % max_x) * (this._tileSize.width + this.spacing) + this.margin, 10);
- rect._origin.y = parseInt(parseInt(gid / max_x, 10) * (this._tileSize.height + this.spacing) + this.margin, 10);
- return rect;
- }
- });
- /**
- * <p>cc.TMXMapInfo contains the information about the map like: <br/>
- *- Map orientation (hexagonal, isometric or orthogonal)<br/>
- *- Tile size<br/>
- *- Map size</p>
- *
- * <p>And it also contains: <br/>
- * - Layers (an array of TMXLayerInfo objects)<br/>
- * - Tilesets (an array of TMXTilesetInfo objects) <br/>
- * - ObjectGroups (an array of TMXObjectGroupInfo objects) </p>
- *
- * <p>This information is obtained from the TMX file. </p>
- * @class
- * @extends cc.SAXParser
- */
- cc.TMXMapInfo = cc.SAXParser.extend(/** @lends cc.TMXMapInfo# */{
- // map orientation
- _orientation:null,
- _mapSize:null,
- _tileSize:null,
- _layers:null,
- _tileSets:null,
- _objectGroups:null,
- _parentElement:null,
- _parentGID:null,
- _layerAttribs:0,
- _storingCharacters:false,
- _properties:null,
- // tmx filename
- _TMXFileName:null,
- //current string
- _currentString:null,
- // tile properties
- _tileProperties:null,
- _resources:"",
- _currentFirstGID:0,
- ctor:function () {
- this._mapSize = cc.SizeZero();
- this._tileSize = cc.SizeZero();
- this._layers = [];
- this._tileSets = [];
- this._objectGroups = [];
- this._properties = [];
- this._tileProperties = {};
- this._currentFirstGID = 0;
- },
- /**
- * @return {Number}
- */
- getOrientation:function () {
- return this._orientation;
- },
- /**
- * @param {Number} Var
- */
- setOrientation:function (Var) {
- this._orientation = Var;
- },
- /**
- * Map width & height
- * @return {cc.Size}
- */
- getMapSize:function () {
- return cc.size(this._mapSize.width,this._mapSize.height);
- },
- /**
- * @param {cc.Size} Var
- */
- setMapSize:function (Var) {
- this._mapSize.width = Var.width;
- this._mapSize.height = Var.height;
- },
- /**
- * Tiles width & height
- * @return {cc.Size}
- */
- getTileSize:function () {
- return cc.size(this._tileSize.width, this._tileSize.height);
- },
- /**
- * @param {cc.Size} Var
- */
- setTileSize:function (Var) {
- this._tileSize.width = Var.width;
- this._tileSize.height = Var.height;
- },
- /**
- * Layers
- * @return {Array}
- */
- getLayers:function () {
- return this._layers;
- },
- /**
- * @param {cc.TMXLayerInfo} Var
- */
- setLayers:function (Var) {
- this._layers.push(Var);
- },
- /**
- * tilesets
- * @return {Array}
- */
- getTilesets:function () {
- return this._tileSets;
- },
- /**
- * @param {cc.TMXTilesetInfo} Var
- */
- setTilesets:function (Var) {
- this._tileSets.push(Var);
- },
- /**
- * ObjectGroups
- * @return {Array}
- */
- getObjectGroups:function () {
- return this._objectGroups;
- },
- /**
- * @param {cc.TMXObjectGroup} Var
- */
- setObjectGroups:function (Var) {
- this._objectGroups.push(Var);
- },
- /**
- * parent element
- * @return {Number}
- */
- getParentElement:function () {
- return this._parentElement;
- },
- /**
- * @param {Number} Var
- */
- setParentElement:function (Var) {
- this._parentElement = Var;
- },
- /**
- * parent GID
- * @return {Number}
- */
- getParentGID:function () {
- return this._parentGID;
- },
- /**
- * @param {Number} Var
- */
- setParentGID:function (Var) {
- this._parentGID = Var;
- },
- /**
- * layer attribute
- * @return {Number}
- */
- getLayerAttribs:function () {
- return this._layerAttribs;
- },
- /**
- * @param {Number} Var
- */
- setLayerAttribs:function (Var) {
- this._layerAttribs = Var;
- },
- /**
- * is string characters?
- * @return {Boolean}
- */
- getStoringCharacters:function () {
- return this._storingCharacters;
- },
- /**
- * @param {Boolean} Var
- */
- setStoringCharacters:function (Var) {
- this._storingCharacters = Var;
- },
- /**
- * Properties
- * @return {Array}
- */
- getProperties:function () {
- return this._properties;
- },
- /**
- * @param {object} Var
- */
- setProperties:function (Var) {
- this._properties = Var;
- },
- /**
- * Initializes a TMX format with a tmx file
- * @param {String} tmxFile
- * @param {String} resourcePath
- * @return {Element}
- */
- initWithTMXFile:function (tmxFile, resourcePath) {
- this._internalInit(tmxFile, resourcePath);
- return this.parseXMLFile(this._TMXFileName);
- //return this.parseXMLFile(cc.FileUtils.getInstance().fullPathForFilename(this._TMXFileName));
- },
- /**
- * initializes a TMX format with an XML string and a TMX resource path
- * @param {String} tmxString
- * @param {String} resourcePath
- * @return {Boolean}
- */
- initWithXML:function (tmxString, resourcePath) {
- this._internalInit(null, resourcePath);
- return this.parseXMLString(tmxString);
- },
- /** Initalises parsing of an XML file, either a tmx (Map) file or tsx (Tileset) file
- * @param {String} tmxFile
- * @param {boolean} [isXmlString=false]
- * @return {Element}
- */
- parseXMLFile:function (tmxFile, isXmlString) {
- isXmlString = isXmlString || false;
- tmxFile = cc.FileUtils.getInstance().fullPathForFilename(tmxFile);
- var mapXML = cc.SAXParser.getInstance().tmxParse(tmxFile, isXmlString);
- var i, j;
- // PARSE <map>
- var map = mapXML.documentElement;
- var version = map.getAttribute('version');
- var orientationStr = map.getAttribute('orientation');
- if (map.nodeName == "map") {
- if (version != "1.0" && version !== null)
- cc.log("cocos2d: TMXFormat: Unsupported TMX version:" + version);
- if (orientationStr == "orthogonal")
- this.setOrientation(cc.TMX_ORIENTATION_ORTHO);
- else if (orientationStr == "isometric")
- this.setOrientation(cc.TMX_ORIENTATION_ISO);
- else if (orientationStr == "hexagonal")
- this.setOrientation(cc.TMX_ORIENTATION_HEX);
- else if (orientationStr !== null)
- cc.log("cocos2d: TMXFomat: Unsupported orientation:" + this.getOrientation());
- var mapSize = cc.size(0, 0);
- mapSize.width = parseFloat(map.getAttribute('width'));
- mapSize.height = parseFloat(map.getAttribute('height'));
- this.setMapSize(mapSize);
- mapSize = cc.size(0, 0);
- mapSize.width = parseFloat(map.getAttribute('tilewidth'));
- mapSize.height = parseFloat(map.getAttribute('tileheight'));
- this.setTileSize(mapSize);
- // The parent element is the map
- var propertyArr = map.querySelectorAll("map > properties > property");
- if (propertyArr) {
- var aPropertyDict = {};
- for (i = 0; i < propertyArr.length; i++) {
- aPropertyDict[propertyArr[i].getAttribute('name')] = propertyArr[i].getAttribute('value');
- }
- this.setProperties(aPropertyDict);
- }
- }
- // PARSE <tileset>
- var tilesets = map.getElementsByTagName('tileset');
- if (map.nodeName !== "map") {
- tilesets = [];
- tilesets.push(map);
- }
- for (i = 0; i < tilesets.length; i++) {
- var selTileset = tilesets[i];
- // If this is an external tileset then start parsing that
- var externalTilesetFilename = selTileset.getAttribute('source');
- if (externalTilesetFilename) {
- //this._currentFirstGID = parseInt(selTileset.getAttribute('firstgid'));
- this.parseXMLFile(cc.FileUtils.getInstance().fullPathFromRelativeFile(externalTilesetFilename, isXmlString ? this._resources + "/" : tmxFile));
- } else {
- var tileset = new cc.TMXTilesetInfo();
- tileset.name = selTileset.getAttribute('name') || "";
- //TODO need fix
- //if(this._currentFirstGID === 0){
- tileset.firstGid = parseInt(selTileset.getAttribute('firstgid')) || 0;
- //}else{
- // tileset.firstGid = this._currentFirstGID;
- // this._currentFirstGID = 0;
- //}
- tileset.spacing = parseInt(selTileset.getAttribute('spacing')) || 0;
- tileset.margin = parseInt(selTileset.getAttribute('margin')) || 0;
- var tilesetSize = cc.size(0, 0);
- tilesetSize.width = parseFloat(selTileset.getAttribute('tilewidth'));
- tilesetSize.height = parseFloat(selTileset.getAttribute('tileheight'));
- tileset._tileSize = tilesetSize;
- var image = selTileset.getElementsByTagName('image')[0];
- var imagename = image.getAttribute('source');
- var num = -1;
- if(this._TMXFileName)
- num = this._TMXFileName.lastIndexOf("/");
- if (num !== -1) {
- var dir = this._TMXFileName.substr(0, num + 1);
- tileset.sourceImage = dir + imagename;
- } else {
- tileset.sourceImage = this._resources + (this._resources ? "/" : "") + imagename;
- }
- this.setTilesets(tileset);
- }
- }
- // PARSE <tile>
- var tiles = map.querySelectorAll('tile');
- if (tiles) {
- for (i = 0; i < tiles.length; i++) {
- var info = this._tileSets[0];
- var t = tiles[i];
- this.setParentGID(parseInt(info.firstGid) + parseInt(t.getAttribute('id') || 0));
- var tp = t.querySelectorAll("properties > property");
- if (tp) {
- var dict = {};
- for (j = 0; j < tp.length; j++) {
- var name = tp[j].getAttribute('name');
- dict[name] = tp[j].getAttribute('value');
- }
- this._tileProperties[this.getParentGID()] = dict;
- }
- }
- }
- // PARSE <layer>
- var layers = map.getElementsByTagName('layer');
- if (layers) {
- for (i = 0; i < layers.length; i++) {
- var selLayer = layers[i];
- var data = selLayer.getElementsByTagName('data')[0];
- var layer = new cc.TMXLayerInfo();
- layer.name = selLayer.getAttribute('name');
- var layerSize = cc.size(0, 0);
- layerSize.width = parseFloat(selLayer.getAttribute('width'));
- layerSize.height = parseFloat(selLayer.getAttribute('height'));
- layer._layerSize = layerSize;
- var visible = selLayer.getAttribute('visible');
- layer.visible = !(visible == "0");
- var opacity = selLayer.getAttribute('opacity') || 1;
- if (opacity)
- layer._opacity = parseInt(255 * parseFloat(opacity));
- else
- layer._opacity = 255;
- layer.offset = cc.p(parseFloat(selLayer.getAttribute('x')) || 0, parseFloat(selLayer.getAttribute('y')) || 0);
- var nodeValue = '';
- for (j = 0; j < data.childNodes.length; j++) {
- nodeValue += data.childNodes[j].nodeValue
- }
- nodeValue = nodeValue.trim();
- // Unpack the tilemap data
- var compression = data.getAttribute('compression');
- var encoding = data.getAttribute('encoding');
- if(compression && compression !== "gzip" && compression !== "zlib"){
- cc.log("cc.TMXMapInfo.parseXMLFile(): unsupported compression method");
- return null;
- }
- switch (compression) {
- case 'gzip':
- layer._tiles = cc.unzipBase64AsArray(nodeValue, 4);
- break;
- case 'zlib':
- var inflator = new Zlib.Inflate(cc.Codec.Base64.decodeAsArray(nodeValue, 1));
- layer._tiles = cc.uint8ArrayToUint32Array(inflator.decompress());
- break;
- case null:
- case '':
- // Uncompressed
- if (encoding == "base64")
- layer._tiles = cc.Codec.Base64.decodeAsArray(nodeValue, 4);
- else if (encoding === "csv") {
- layer._tiles = [];
- var csvTiles = nodeValue.split(',');
- for (var csvIdx = 0; csvIdx < csvTiles.length; csvIdx++)
- layer._tiles.push(parseInt(csvTiles[csvIdx]));
- } else {
- //XML format
- var selDataTiles = data.getElementsByTagName("tile");
- layer._tiles = [];
- for (var xmlIdx = 0; xmlIdx < selDataTiles.length; xmlIdx++)
- layer._tiles.push(parseInt(selDataTiles[xmlIdx].getAttribute("gid")));
- }
- break;
- default:
- if(this.getLayerAttribs() == cc.TMX_LAYER_ATTRIB_NONE)
- cc.log("cc.TMXMapInfo.parseXMLFile(): Only base64 and/or gzip/zlib maps are supported");
- break;
- }
- // The parent element is the last layer
- var layerProps = selLayer.querySelectorAll("properties > property");
- if (layerProps) {
- var layerProp = {};
- for (j = 0; j < layerProps.length; j++) {
- layerProp[layerProps[j].getAttribute('name')] = layerProps[j].getAttribute('value');
- }
- layer.setProperties(layerProp);
- }
- this.setLayers(layer);
- }
- }
- // PARSE <objectgroup>
- var objectGroups = map.getElementsByTagName('objectgroup');
- if (objectGroups) {
- for (i = 0; i < objectGroups.length; i++) {
- var selGroup = objectGroups[i];
- var objectGroup = new cc.TMXObjectGroup();
- objectGroup.setGroupName(selGroup.getAttribute('name'));
- objectGroup.setPositionOffset(cc.p(parseFloat(selGroup.getAttribute('x')) * this.getTileSize().width || 0,
- parseFloat(selGroup.getAttribute('y')) * this.getTileSize().height || 0));
- var groupProps = selGroup.querySelectorAll("objectgroup > properties > property");
- if (groupProps) {
- for (j = 0; j < groupProps.length; j++) {
- var groupProp = {};
- groupProp[groupProps[j].getAttribute('name')] = groupProps[j].getAttribute('value');
- // Add the property to the layer
- objectGroup.setProperties(groupProp);
- }
- }
- var objects = selGroup.querySelectorAll('object');
- if (objects) {
- for (j = 0; j < objects.length; j++) {
- var selObj = objects[j];
- // The value for "type" was blank or not a valid class name
- // Create an instance of TMXObjectInfo to store the object and its properties
- var objectProp = {};
- // Set the name of the object to the value for "name"
- objectProp["name"] = selObj.getAttribute('name') || "";
- // Assign all the attributes as key/name pairs in the properties dictionary
- objectProp["type"] = selObj.getAttribute('type') || "";
- objectProp["x"] = parseInt(selObj.getAttribute('x') || 0) + objectGroup.getPositionOffset().x;
- var y = parseInt(selObj.getAttribute('y') || 0) + objectGroup.getPositionOffset().y;
- objectProp["width"] = parseInt(selObj.getAttribute('width')) || 0;
- objectProp["height"] = parseInt(selObj.getAttribute('height')) || 0;
- // Correct y position. (Tiled uses Flipped, cocos2d uses Standard)
- objectProp["y"] = parseInt(this.getMapSize().height * this.getTileSize().height) - y - objectProp["height"];
- var docObjProps = selObj.querySelectorAll("properties > property");
- if (docObjProps) {
- for (var k = 0; k < docObjProps.length; k++)
- objectProp[docObjProps[k].getAttribute('name')] = docObjProps[k].getAttribute('value');
- }
- //polygon
- var polygonProps = selObj.querySelectorAll("polygon");
- if(polygonProps && polygonProps.length > 0) {
- var selPgPointStr = polygonProps[0].getAttribute('points');
- if(selPgPointStr)
- objectProp["polygonPoints"] = this._parsePointsString(selPgPointStr);
- }
- //polyline
- var polylineProps = selObj.querySelectorAll("polyline");
- if(polylineProps && polylineProps.length > 0) {
- var selPlPointStr = polylineProps[0].getAttribute('points');
- if(selPlPointStr)
- objectProp["polylinePoints"] = this._parsePointsString(selPlPointStr);
- }
- // Add the object to the objectGroup
- objectGroup.setObjects(objectProp);
- }
- }
- this.setObjectGroups(objectGroup);
- }
- }
- return map;
- },
- _parsePointsString:function(pointsString){
- if(!pointsString)
- return null;
- var points = [];
- var pointsStr = pointsString.split(' ');
- for(var i = 0; i < pointsStr.length; i++){
- var selPointStr = pointsStr[i].split(',');
- points.push({'x':selPointStr[0], 'y':selPointStr[1]});
- }
- return points;
- },
- /**
- * initializes parsing of an XML string, either a tmx (Map) string or tsx (Tileset) string
- * @param {String} xmlString
- * @return {Boolean}
- */
- parseXMLString:function (xmlString) {
- return this.parseXMLFile(xmlString, true);
- },
- /**
- * @return {object}
- */
- getTileProperties:function () {
- return this._tileProperties;
- },
- /**
- * @param {object} tileProperties
- */
- setTileProperties:function (tileProperties) {
- this._tileProperties.push(tileProperties);
- },
- /**
- * @return {String}
- */
- getCurrentString:function () {
- return this._currentString;
- },
- /**
- * @param {String} currentString
- */
- setCurrentString:function (currentString) {
- this._currentString = currentString;
- },
- /**
- * @return {String}
- */
- getTMXFileName:function () {
- return this._TMXFileName;
- },
- /**
- * @param {String} fileName
- */
- setTMXFileName:function (fileName) {
- this._TMXFileName = fileName;
- },
- _internalInit:function (tmxFileName, resourcePath) {
- this._tileSets.length = 0;
- this._layers.length = 0;
- //this._TMXFileName = cc.FileUtils.getInstance().fullPathForFilename(tmxFileName);
- this._TMXFileName = tmxFileName;
- if (resourcePath)
- this._resources = resourcePath;
- this._objectGroups.length = 0;
- this._properties.length = 0;
- this._tileProperties.length = 0;
- // tmp vars
- this._currentString = "";
- this._storingCharacters = false;
- this._layerAttribs = cc.TMX_LAYER_ATTRIB_NONE;
- this._parentElement = cc.TMX_PROPERTY_NONE;
- this._currentFirstGID = 0;
- }
- });
- /**
- * Creates a TMX Format with a tmx file
- * @param {String} tmxFile
- * @param {String} resourcePath
- * @return {cc.TMXMapInfo}
- */
- cc.TMXMapInfo.create = function (tmxFile, resourcePath) {
- var ret = new cc.TMXMapInfo();
- if (ret.initWithTMXFile(tmxFile, resourcePath))
- return ret;
- return null;
- };
- /**
- * creates a TMX Format with an XML string and a TMX resource path
- * @param {String} tmxString
- * @param {String} resourcePath
- * @return {cc.TMXMapInfo}
- */
- cc.TMXMapInfo.createWithXML = function (tmxString, resourcePath) {
- var ret = new cc.TMXMapInfo();
- if (ret.initWithXML(tmxString, resourcePath))
- return ret;
- return null;
- };
|