From 802650165b6e854eb898991b3d4d488b99fb29a2 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Tue, 23 Feb 2016 16:40:52 +0800 Subject: [PATCH] fix label size not initialized in play mode --- cocos2d/core/components/CCLabel.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/cocos2d/core/components/CCLabel.js b/cocos2d/core/components/CCLabel.js index 3e5b012986..90606ea19b 100644 --- a/cocos2d/core/components/CCLabel.js +++ b/cocos2d/core/components/CCLabel.js @@ -271,11 +271,14 @@ var Label = cc.Class({ // update node size (this will also invoke the size-changed event) _updateNodeSize: function () { - if (this.overflow === Overflow.NONE) { - this.node.setContentSize(this._sgNode.getContentSize()); - } - if ( !this.node._sizeProvider ) { - this.node._sizeProvider = this._sgNode; + var initialized = this._sgNode && this._sgNode.parent; + if (initialized) { + if (this.overflow === Overflow.NONE) { + this.node.setContentSize(this._sgNode.getContentSize()); + } + if ( !this.node._sizeProvider ) { + this.node._sizeProvider = this._sgNode; + } } } });