From 4d3a92111615d8748b07aed39bbaa9f146e16826 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=AE=B6=E8=BE=89?= <35832931+ColinCollins@users.noreply.github.com> Date: Mon, 7 May 2018 11:46:38 +0800 Subject: [PATCH 1/4] add a new judgement about mobile platform type in wecaht devtools (#2623) --- cocos2d/core/platform/CCSys.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cocos2d/core/platform/CCSys.js b/cocos2d/core/platform/CCSys.js index ffed7d2540..be76e17638 100644 --- a/cocos2d/core/platform/CCSys.js +++ b/cocos2d/core/platform/CCSys.js @@ -562,6 +562,15 @@ else if (CC_WECHATGAME) { else if (env.platform === "ios") { sys.os = sys.OS_IOS; } + else if (env.platform === 'devtools') { + var system = env.system.toLowerCase(); + if (system.indexOf('android') > -1) { + sys.os = sys.OS_ANDROID; + } + else if (system.indexOf('ios') > -1) { + sys.os = sys.OS_IOS; + } + } var version = /[\d\.]+/.exec(env.system); sys.osVersion = version[0]; From f4568fada0860d194aa389bfa732d49786656356 Mon Sep 17 00:00:00 2001 From: Knox Date: Mon, 7 May 2018 14:24:41 +0800 Subject: [PATCH 2/4] optimization audio label texture2d , fix sprite bug (#2631) * optimization audio label texture2d , fix sprite bug * refine code --- CCBoot.js | 2 +- cocos2d/audio/CCAudio.js | 19 ++++++++++++------- cocos2d/core/label/CCSGLabel.js | 3 ++- cocos2d/core/platform/CCSys.js | 2 +- cocos2d/core/sprites/CCScale9Sprite.js | 5 +---- cocos2d/core/textures/CCTexture2D.js | 1 + 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/CCBoot.js b/CCBoot.js index 98fc89518c..ab629dedca 100644 --- a/CCBoot.js +++ b/CCBoot.js @@ -32,7 +32,7 @@ cc._LogInfos = cc._LogInfos || {}; * @property {String} ENGINE_VERSION */ var engineVersion; -engineVersion = '1.6.0'; +engineVersion = '1.9.0'; window['CocosEngine'] = cc.ENGINE_VERSION = engineVersion; /** diff --git a/cocos2d/audio/CCAudio.js b/cocos2d/audio/CCAudio.js index 86635d7e19..70e20bc8c6 100644 --- a/cocos2d/audio/CCAudio.js +++ b/cocos2d/audio/CCAudio.js @@ -138,10 +138,15 @@ Audio.State = { }; proto.mount = function (elem) { - if (sys.platform === sys.WECHAT_GAME || elem instanceof HTMLElement) { - this._element = document.createElement('audio'); - this._element.src = elem.src; - this._audioType = Audio.Type.DOM; + if (elem instanceof HTMLElement) { + if (CC_QQPLAY || CC_WECHATGAME) { + this._element = elem; + } + else { + this._element = document.createElement('audio'); + this._element.src = elem.src; + this._audioType = Audio.Type.DOM; + } } else { this._element = new WebAudioElement(elem, this); this._audioType = Audio.Type.WEBAUDIO; @@ -157,7 +162,7 @@ Audio.State = { this.emit('play'); this._state = Audio.State.PLAYING; - if (sys.platform !== sys.WECHAT_GAME && + if (!(CC_QQPLAY || CC_WECHATGAME) && this._audioType === Audio.Type.DOM && this._element.paused) { touchPlayList.push({ instance: this, offset: 0, audio: this._element }); @@ -242,7 +247,7 @@ Audio.State = { proto.setCurrentTime = function (num) { if (!this._element) return; this._unbindEnded(); - if (sys.platform !== sys.WECHAT_GAME) { + if (!(CC_QQPLAY || CC_WECHATGAME)) { this._bindEnded(function () { this._bindEnded(); }.bind(this)); @@ -374,7 +379,7 @@ var WebAudioElement = function (buffer, audio) { var self = this; clearTimeout(this._currextTimer); this._currextTimer = setTimeout(function () { - if (sys.platform !== sys.WECHAT_GAME && self._context.currentTime === 0) { + if (!(CC_QQPLAY || CC_WECHATGAME) && self._context.currentTime === 0) { touchPlayList.push({ instance: self._audio, offset: offset, diff --git a/cocos2d/core/label/CCSGLabel.js b/cocos2d/core/label/CCSGLabel.js index 019624a829..564c4a2c7b 100644 --- a/cocos2d/core/label/CCSGLabel.js +++ b/cocos2d/core/label/CCSGLabel.js @@ -1272,12 +1272,13 @@ _ccsg.Label.pool = new JS.Pool(function (label) { label._resetBMFont(); label._renderCmd._labelCanvas.width = 1; label._renderCmd._labelCanvas.height = 1; + label._renderCmd._texture.releaseTexture(); if (CC_DEV) { cc.assert(!label._parent, 'Recycling label\'s parent should be null!'); } label._updateLabel(); return true; -}, 20); +}, 120); _ccsg.Label.pool.get = function (string, fontAsset) { var label = this._get(); diff --git a/cocos2d/core/platform/CCSys.js b/cocos2d/core/platform/CCSys.js index be76e17638..f26fab9100 100644 --- a/cocos2d/core/platform/CCSys.js +++ b/cocos2d/core/platform/CCSys.js @@ -623,7 +623,7 @@ else if (CC_QQPLAY) { var version = /[\d\.]+/.exec(env.version); sys.osVersion = version[0]; - sys.osMainVersion = parseInt(osVersion.split('.')[0]); + sys.osMainVersion = parseInt(sys.osVersion.split('.')[0]); sys.browserType = sys.BROWSER_TYPE_QQ_PLAY; sys.browserVersion = 0; diff --git a/cocos2d/core/sprites/CCScale9Sprite.js b/cocos2d/core/sprites/CCScale9Sprite.js index eb8f76b452..ad71c77959 100644 --- a/cocos2d/core/sprites/CCScale9Sprite.js +++ b/cocos2d/core/sprites/CCScale9Sprite.js @@ -1194,10 +1194,7 @@ cc.Scale9Sprite = _ccsg.Node.extend({ this._renderCmd._needDraw = false; var self = this; var onResourceDataLoaded = function () { - if (!self.isValid) { - return; - } - if (cc.sizeEqualToSize(self._contentSize, cc.size(0, 0))) { + if (self._spriteFrame && cc.sizeEqualToSize(self._contentSize, cc.size(0, 0))) { self.setContentSize(self._spriteFrame._rect); } self._renderCmd._needDraw = true; diff --git a/cocos2d/core/textures/CCTexture2D.js b/cocos2d/core/textures/CCTexture2D.js index 299f84ea4e..09b5db8416 100644 --- a/cocos2d/core/textures/CCTexture2D.js +++ b/cocos2d/core/textures/CCTexture2D.js @@ -427,6 +427,7 @@ var Texture2D = cc.Class(/** @lends cc.Texture2D# */{ releaseTexture: function () { if (this._gl && this._glID !== null) { this._gl.deleteTexture(this._glID); + this._glID = null; } }, From fbaf432017fa2cde9d028afae8281b39f913d29b Mon Sep 17 00:00:00 2001 From: PP Date: Tue, 8 May 2018 10:23:19 +0800 Subject: [PATCH 3/4] remove setTimeout when stop audio (#2639) --- cocos2d/audio/CCAudio.js | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/cocos2d/audio/CCAudio.js b/cocos2d/audio/CCAudio.js index 70e20bc8c6..d8d91aa9ef 100644 --- a/cocos2d/audio/CCAudio.js +++ b/cocos2d/audio/CCAudio.js @@ -204,17 +204,9 @@ Audio.State = { proto.stop = function () { if (!this._element) return; - if (CC_WECHATGAME) { - setTimeout(function () { - try { - this._element.currentTime = 0; - } catch (error) {} - }.bind(this), 0); - } else { - try { - this._element.currentTime = 0; - } catch (error) {} - } + try { + this._element.currentTime = 0; + } catch (error) {} this._element.pause(); // remove touchPlayList for (var i=0; i Date: Tue, 8 May 2018 11:14:16 +0800 Subject: [PATCH 4/4] optimization label memory on qqplay and wechatgame (#2643) --- cocos2d/core/label/CCSGLabel.js | 6 ++---- cocos2d/core/label/CCSGLabelCanvasRenderCmd.js | 2 +- cocos2d/core/label/CCSGLabelWebGLRenderCmd.js | 8 +++++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cocos2d/core/label/CCSGLabel.js b/cocos2d/core/label/CCSGLabel.js index 564c4a2c7b..acb90e6ad8 100644 --- a/cocos2d/core/label/CCSGLabel.js +++ b/cocos2d/core/label/CCSGLabel.js @@ -157,7 +157,7 @@ _ccsg.Label = _ccsg.Node.extend({ _ccsg.Node.prototype.ctor.call(this); this.setAnchorPoint(0.5, 0.5); - _ccsg.Node.prototype.setContentSize.call(this, 128, 128); + _ccsg.Node.prototype.setContentSize.call(this, 10, 10); this._blendFunc = cc.BlendFunc._alphaNonPremultiplied(); this._imageOffset = cc.p(0, 0); @@ -1270,8 +1270,6 @@ _ccsg.Label.pool = new JS.Pool(function (label) { label._fontHandle = ""; label._labelType = 0; label._resetBMFont(); - label._renderCmd._labelCanvas.width = 1; - label._renderCmd._labelCanvas.height = 1; label._renderCmd._texture.releaseTexture(); if (CC_DEV) { cc.assert(!label._parent, 'Recycling label\'s parent should be null!'); @@ -1294,7 +1292,7 @@ _ccsg.Label.pool.get = function (string, fontAsset) { label._position.x = 0; label._position.y = 0; label.setAnchorPoint(0.5, 0.5); - _ccsg.Node.prototype.setContentSize.call(label, 128, 128); + _ccsg.Node.prototype.setContentSize.call(label, 10, 10); if (isAsset) { label.setFontAsset(fontAsset); diff --git a/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js b/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js index 3902eb1402..41db589143 100644 --- a/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js +++ b/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js @@ -399,7 +399,7 @@ }; proto._updateTexture = function() { - this._labelContext.clearRect(0, 0, this._labelCanvas.width, this._labelCanvas.height); + this._labelContext.clearRect(0, 0, this._canvasSize.width, this._canvasSize.height); this._labelContext.font = this._fontDesc; diff --git a/cocos2d/core/label/CCSGLabelWebGLRenderCmd.js b/cocos2d/core/label/CCSGLabelWebGLRenderCmd.js index 81165fb542..fa3fc6f2f6 100644 --- a/cocos2d/core/label/CCSGLabelWebGLRenderCmd.js +++ b/cocos2d/core/label/CCSGLabelWebGLRenderCmd.js @@ -30,12 +30,14 @@ http://www.angelcode.com/products/bmfont/ (Free, Windows only) ****************************************************************************/ +var _sharedLabelCanvas; _ccsg.Label.WebGLRenderCmd = function(renderableObject){ this._rootCtor(renderableObject); this._needDraw = true; this._texture = new cc.Texture2D(); - this._labelCanvas = document.createElement("canvas"); + _sharedLabelCanvas = _sharedLabelCanvas || document.createElement('canvas'); + this._labelCanvas = _sharedLabelCanvas; this._texture.initWithElement(this._labelCanvas); this._labelContext = this._labelCanvas.getContext("2d"); @@ -65,8 +67,8 @@ proto.updateTransform = function (parentCmd) { this.originUpdateTransform(parentCmd); var node = this._node, - lx = 0, rx = this._labelCanvas.width, - by = 0, ty = this._labelCanvas.height, + lx = 0, rx = this._node.width, + by = 0, ty = this._node.height, wt = this._worldTransform; var vert = this._vertices;