/**************************************************************************** Copyright (c) 2013-2016 Chukong Technologies Inc. http://www.cocos.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated engine source code (the "Software"), a limited, worldwide, royalty-free, non-assignable, revocable and non-exclusive license to use Cocos Creator solely to develop games on your target platforms. You shall not use Cocos Creator software for developing other software or tools that's used for developing games. You are not granted to publish, distribute, sublicense, and/or sell copies of Cocos Creator. The software or tools in this License Agreement are licensed, not sold. Chukong Aipu reserves all rights not expressly granted to you. 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. ****************************************************************************/ /** * Render the TMX layer. * @class TiledLayer * @extends _SGComponent */ var TiledLayer = cc.Class({ name: 'cc.TiledLayer', // Inherits from the abstract class directly, // because TiledLayer not create or maintains the sgNode by itself. extends: cc._SGComponent, onEnable: function() { if (this._sgNode) { this._sgNode.setVisible(true); } }, onDisable: function() { if (this._sgNode) { this._sgNode.setVisible(false); } }, //onDestroy: function () { // if ( this.node._sizeProvider === this._sgNode ) { // this.node._sizeProvider = null; // } // this._removeSgNode(); //}, _initSgNode: function() { var sgNode = this._sgNode; if ( !sgNode ) { return; } if ( !this.enabledInHierarchy ) { sgNode.setVisible(false); } if ( !this.node._sizeProvider ) { this.node._sizeProvider = sgNode; } var node = this.node; sgNode.setAnchorPoint(node.getAnchorPoint()); }, _replaceSgNode: function(sgNode) { if (sgNode === this._sgNode) { return; } // Remove the sgNode before this._removeSgNode(); if ( this.node._sizeProvider === this._sgNode ) { this.node._sizeProvider = null; } if (sgNode && sgNode instanceof _ccsg.TMXLayer) { this._sgNode = sgNode; // retain the new sgNode, it will be released in _removeSgNode this._sgNode.retain(); this._initSgNode(); } else { this._sgNode = null; } }, /** * Gets the layer name * @method getLayerName * @return {String} */ getLayerName: function() { if (this._sgNode) { return this._sgNode.getLayerName(); } return ''; }, /** * Set the layer name * @method SetLayerName * @param {String} layerName */ setLayerName:function (layerName) { if (this._sgNode) { this._sgNode.setLayerName(layerName); } }, /** * Return the value for the specific property name * @method getProperty * @param {String} propertyName * @return {*} */ getProperty:function (propertyName) { if (this._sgNode) { return this._sgNode.getProperty(propertyName); } return null; }, /** * Returns the position in pixels of a given tile coordinate * @method getPositionAt * @param {Vec2|Number} pos position or x * @param {Number} [y] * @return {Vec2} */ getPositionAt:function (pos, y) { if (this._sgNode) { return this._sgNode.getPositionAt(pos, y); } return null; }, /** * Removes a tile at given tile coordinate * @method removeTileAt * @param {Vec2|Number} pos position or x * @param {Number} [y] */ removeTileAt:function (pos, y) { if (this._sgNode) { this._sgNode.removeTileAt(pos, y); } }, /** *
Sets the tile gid (gid = tile global id) at a given tile coordinate.
* The Tile GID can be obtained by using the method "tileGIDAt" or by using the TMX editor . Tileset Mgr +1.
* If a tile is already placed at that position, then it will be removed.
Returns the tile (_ccsg.Sprite) at a given a tile coordinate.
* The returned _ccsg.Sprite will be already added to the _ccsg.TMXLayer. Don't add it again.
* The _ccsg.Sprite can be treated like any other _ccsg.Sprite: rotated, scaled, translated, opacity, color, etc.
* You can remove either by calling:
* - layer.removeChild(sprite, cleanup);
* - or layer.removeTileAt(ccp(x,y));
Dealloc the map that contains the tile position from memory.
* Unless you want to know at runtime the tiles positions, you can safely call this method.
* If you are going to call layer.getTileGIDAt() then, don't release the map