From 2edeb68f5247d09762f183753092f79faf7cec1f Mon Sep 17 00:00:00 2001 From: pandamicro Date: Tue, 21 Aug 2018 00:11:41 +0800 Subject: [PATCH] Support lazy loading image mask (#3123) --- cocos2d/core/components/CCMask.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cocos2d/core/components/CCMask.js b/cocos2d/core/components/CCMask.js index f20ef0fba2..f401cd5a5c 100644 --- a/cocos2d/core/components/CCMask.js +++ b/cocos2d/core/components/CCMask.js @@ -257,7 +257,17 @@ let Mask = cc.Class({ onEnable () { this._super(); - if (this._type !== MaskType.IMAGE_STENCIL) { + if (this._type === MaskType.IMAGE_STENCIL) { + if (!this._spriteFrame || !this._spriteFrame.textureLoaded()) { + // Do not render when sprite frame is not ready + this.markForRender(false); + if (this._spriteFrame) { + this._spriteFrame.once('load', this._onTextureLoaded, this); + this._spriteFrame.ensureLoadTexture(); + } + } + } + else { this._updateGraphics(); }