From c4334878f8236b1768f370c387d13bb7604594db Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Tue, 5 Jun 2018 19:25:43 +0800 Subject: [PATCH] fixed empty tiledlayer error (#2802) --- cocos2d/tilemap/CCTiledLayer.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/cocos2d/tilemap/CCTiledLayer.js b/cocos2d/tilemap/CCTiledLayer.js index 8c17ac4a74..93e294c0f4 100644 --- a/cocos2d/tilemap/CCTiledLayer.js +++ b/cocos2d/tilemap/CCTiledLayer.js @@ -499,7 +499,7 @@ let TiledLayer = cc.Class({ this._textures[i] = tex; this._fillTextureGrids(tilesetInfo, i); if (tileset === tilesetInfo) { - this.setTexture(tex); + this._texture = tex; } } } @@ -523,6 +523,8 @@ let TiledLayer = cc.Class({ } this._useAutomaticVertexZ = false; this._vertexZvalue = 0; + + this._activateMaterial(); }, _calculateLayerOffset (pos) { @@ -611,12 +613,21 @@ let TiledLayer = cc.Class({ }, _activateMaterial () { - if (this._material) return; - - let material = new SpriteMaterial(); - // TODO: old texture in material have been released by loader - material.texture = this._texture; - material.useColor = false; + let material = this._material; + if (!material) { + material = this._material = new SpriteMaterial(); + material.useColor = false; + } + + if (this._texture) { + // TODO: old texture in material have been released by loader + material.texture = this._texture; + this.markForUpdateRenderData(true); + this.markForRender(true); + } + else { + this.disableRender(); + } this.setMaterial(material); },