From c7668f6e1caccf3e57b0bcd4d531a89b35f8a8ae Mon Sep 17 00:00:00 2001 From: pandamicro Date: Tue, 14 Aug 2018 18:23:07 +0800 Subject: [PATCH 01/53] Fix tiled sprite render issue with rotated frame (#3087) --- .../renderer/webgl/assemblers/sprite/tiled.js | 118 +++++++----------- 1 file changed, 45 insertions(+), 73 deletions(-) diff --git a/cocos2d/core/renderer/webgl/assemblers/sprite/tiled.js b/cocos2d/core/renderer/webgl/assemblers/sprite/tiled.js index 84559e63a0..45e048b480 100644 --- a/cocos2d/core/renderer/webgl/assemblers/sprite/tiled.js +++ b/cocos2d/core/renderer/webgl/assemblers/sprite/tiled.js @@ -72,59 +72,9 @@ module.exports = { let data = renderData._data; renderData.dataLength = Math.max(8, row+1, col+1); - let l, b, r, t; - if (!frame._rotated) { - l = (rect.x) / texw; - r = (rect.x + rectWidth) / texw; - b = (rect.y + rectHeight) / texh; - t = (rect.y) / texh; - - data[0].u = l; - data[0].v = b; - data[1].u = r; - data[1].v = b; - data[2].u = l; - data[2].v = t; - data[3].u = r; - data[3].v = t; - - data[4].u = l; - data[4].v = b; - data[5].u = l + (r-l) * Math.min(1, hRepeat - col + 1); - data[5].v = b; - data[6].u = l; - data[6].v = b + (t-b) * Math.min(1, vRepeat - row + 1); - data[7].u = data[5].u; - data[7].v = data[6].v; - } else { - l = (rect.x) / texw; - r = (rect.x + rectHeight) / texw; - b = (rect.y + rectWidth) / texh; - t = (rect.y) / texh; - - data[0].u = l; - data[0].v = t; - data[1].u = l; - data[1].v = b; - data[2].u = r; - data[2].v = t; - data[3].u = r; - data[3].v = b; - - data[4].u = l; - data[4].v = t; - data[5].u = l; - data[5].v = t + (b - t) * Math.min(1, vRepeat - col + 1); - data[6].u = l + (r - l) * Math.min(1, hRepeat - row + 1); - data[6].v = t; - data[7].u = data[5].u; - data[7].v = data[6].v; - } - for (let i = 0; i <= col; ++i) { data[i].x = Math.min(rectWidth * i, contentWidth) - appx; } - for (let i = 0; i <= row; ++i) { data[i].y = Math.min(rectHeight * i, contentHeight) - appy; } @@ -154,7 +104,8 @@ module.exports = { let vbuf = buffer._vData, ibuf = buffer._iData; - // + let rotated = sprite.spriteFrame._rotated; + let uv = sprite.spriteFrame.uv; let rect = sprite.spriteFrame._rect; let contentWidth = Math.abs(node.width); let contentHeight = Math.abs(node.height); @@ -167,39 +118,60 @@ module.exports = { let a = matrix.m00, b = matrix.m01, c = matrix.m04, d = matrix.m05, tx = matrix.m12, ty = matrix.m13; - let x, x1, y, y1, lastx, lasty; + let x, x1, y, y1, coefu, coefv; for (let yindex = 0, ylength = row; yindex < ylength; ++yindex) { y = data[yindex].y; y1 = data[yindex+1].y; + coefv = Math.min(1, vRepeat - yindex); for (let xindex = 0, xlength = col; xindex < xlength; ++xindex) { - lasty = yindex + 1 === ylength; - lastx = xindex + 1 === xlength; + coefu = Math.min(1, hRepeat - xindex); x = data[xindex].x; x1 = data[xindex+1].x; + // Vertex // lb - vbuf[vertexOffset++] = x * a + y * c + tx; - vbuf[vertexOffset++] = x * b + y * d + ty; - vbuf[vertexOffset++] = lastx ? data[4].u : data[0].u; - vbuf[vertexOffset++] = lasty ? data[4].v : data[0].v; - + vbuf[vertexOffset] = x * a + y * c + tx; + vbuf[vertexOffset+1] = x * b + y * d + ty; // rb - vbuf[vertexOffset++] = x1 * a + y * c + tx; - vbuf[vertexOffset++] = x1 * b + y * d + ty; - vbuf[vertexOffset++] = lastx ? data[5].u : data[1].u; - vbuf[vertexOffset++] = lasty ? data[5].v : data[1].v; - + vbuf[vertexOffset+4] = x1 * a + y * c + tx; + vbuf[vertexOffset+5] = x1 * b + y * d + ty; // lt - vbuf[vertexOffset++] = x * a + y1 * c + tx; - vbuf[vertexOffset++] = x * b + y1 * d + ty; - vbuf[vertexOffset++] = lastx ? data[6].u : data[2].u; - vbuf[vertexOffset++] = lasty ? data[6].v : data[2].v; - + vbuf[vertexOffset+8] = x * a + y1 * c + tx; + vbuf[vertexOffset+9] = x * b + y1 * d + ty; // rt - vbuf[vertexOffset++] = x1 * a + y1 * c + tx; - vbuf[vertexOffset++] = x1 * b + y1 * d + ty; - vbuf[vertexOffset++] = lastx ? data[7].u : data[3].u; - vbuf[vertexOffset++] = lasty ? data[7].v : data[3].v; + vbuf[vertexOffset+12] = x1 * a + y1 * c + tx; + vbuf[vertexOffset+13] = x1 * b + y1 * d + ty; + + // UV + if (rotated) { + // lb + vbuf[vertexOffset+2] = uv[0]; + vbuf[vertexOffset+3] = uv[1]; + // rb + vbuf[vertexOffset+6] = uv[0]; + vbuf[vertexOffset+7] = uv[1] + (uv[7] - uv[1]) * coefu; + // lt + vbuf[vertexOffset+10] = uv[0] + (uv[6] - uv[0]) * coefv; + vbuf[vertexOffset+11] = uv[1]; + // rt + vbuf[vertexOffset+14] = vbuf[vertexOffset+10]; + vbuf[vertexOffset+15] = vbuf[vertexOffset+7]; + } + else { + // lb + vbuf[vertexOffset+2] = uv[0]; + vbuf[vertexOffset+3] = uv[1]; + // rb + vbuf[vertexOffset+6] = uv[0] + (uv[6] - uv[0]) * coefu; + vbuf[vertexOffset+7] = uv[1]; + // lt + vbuf[vertexOffset+10] = uv[0]; + vbuf[vertexOffset+11] = uv[1] + (uv[7] - uv[1]) * coefv; + // rt + vbuf[vertexOffset+14] = vbuf[vertexOffset+6]; + vbuf[vertexOffset+15] = vbuf[vertexOffset+11]; + } + vertexOffset += 16; } } From 884ba9a8bc7775233744ad1122374d8bc0905194 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Tue, 14 Aug 2018 18:31:46 +0800 Subject: [PATCH 02/53] Fix Label not moved by anchor change (#3091) --- cocos2d/core/components/CCLabel.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cocos2d/core/components/CCLabel.js b/cocos2d/core/components/CCLabel.js index e1d4380cae..848df65585 100644 --- a/cocos2d/core/components/CCLabel.js +++ b/cocos2d/core/components/CCLabel.js @@ -464,6 +464,7 @@ let Label = cc.Class({ // Keep track of Node size this.node.on(cc.Node.EventType.SIZE_CHANGED, this._updateRenderData, this); + this.node.on(cc.Node.EventType.ANCHOR_CHANGED, this._updateRenderData, this); this._checkStringEmpty(); this._updateAssembler(); @@ -473,6 +474,7 @@ let Label = cc.Class({ onDisable () { this._super(); this.node.off(cc.Node.EventType.SIZE_CHANGED, this._updateRenderData, this); + this.node.off(cc.Node.EventType.ANCHOR_CHANGED, this._updateRenderData, this); }, onDestroy () { From d25d3d8fc1197c37d42e7293cc1024f8fe60ee37 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Wed, 15 Aug 2018 09:34:15 +0800 Subject: [PATCH 03/53] Fix color type issue in 2.0.0 ParticleSystem (#3092) --- cocos2d/core/assets/CCAsset.js | 1 - cocos2d/particle/CCParticleSystem.js | 27 +++++++++++++++++++-------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/cocos2d/core/assets/CCAsset.js b/cocos2d/core/assets/CCAsset.js index faee6211a3..fceba18b02 100644 --- a/cocos2d/core/assets/CCAsset.js +++ b/cocos2d/core/assets/CCAsset.js @@ -25,7 +25,6 @@ ****************************************************************************/ var RawAsset = require('./CCRawAsset'); -var js = cc.js; /** * !#en diff --git a/cocos2d/particle/CCParticleSystem.js b/cocos2d/particle/CCParticleSystem.js index 7053b17f7f..98946b8ed6 100644 --- a/cocos2d/particle/CCParticleSystem.js +++ b/cocos2d/particle/CCParticleSystem.js @@ -363,11 +363,12 @@ var properties = { /** * !#en Start color of each particle. * !#zh 粒子初始颜色。 - * @property {Object} startColor + * @property {cc.Color} startColor * @default {r: 255, g: 255, b: 255, a: 255} */ _startColor: null, startColor: { + type: cc.Color, get () { return this._startColor; }, @@ -381,11 +382,12 @@ var properties = { /** * !#en Variation of the start color. * !#zh 粒子初始颜色变化范围。 - * @property {Object} startColorVar + * @property {cc.Color} startColorVar * @default {r: 0, g: 0, b: 0, a: 0} */ _startColorVar: null, startColorVar: { + type: cc.Color, get () { return this._startColorVar; }, @@ -399,11 +401,12 @@ var properties = { /** * !#en Ending color of each particle. * !#zh 粒子结束颜色。 - * @property {Object} endColor + * @property {cc.Color} endColor * @default {r: 255, g: 255, b: 255, a: 0} */ _endColor: null, endColor: { + type: cc.Color, get () { return this._endColor; }, @@ -417,11 +420,12 @@ var properties = { /** * !#en Variation of the end color. * !#zh 粒子结束颜色变化范围。 - * @property {Object} endColorVar + * @property {cc.Color} endColorVar * @default {r: 0, g: 0, b: 0, a: 0} */ _endColorVar: null, endColorVar: { + type: cc.Color, get () { return this._endColorVar; }, @@ -810,6 +814,13 @@ var ParticleSystem = cc.Class({ this.resetSystem(); } } + // Upgrade color type from v2.0.0 + if (CC_EDITOR && !(this._startColor instanceof cc.Color)) { + this._startColor = cc.color(this._startColor); + this._startColorVar = cc.color(this._startColorVar); + this._endColor = cc.color(this._endColor); + this._endColorVar = cc.color(this._endColorVar); + } }, onLoad () { @@ -1002,25 +1013,25 @@ var ParticleSystem = cc.Class({ this.dstBlendFactor = parseInt(dict["blendFuncDestination"] || macro.ONE_MINUS_SRC_ALPHA); // color - var locStartColor = this.startColor; + var locStartColor = this._startColor; locStartColor.r = parseFloat(dict["startColorRed"] || 1) * 255; locStartColor.g = parseFloat(dict["startColorGreen"] || 1) * 255; locStartColor.b = parseFloat(dict["startColorBlue"] || 1) * 255; locStartColor.a = parseFloat(dict["startColorAlpha"] || 1) * 255; - var locStartColorVar = this.startColorVar; + var locStartColorVar = this._startColorVar; locStartColorVar.r = parseFloat(dict["startColorVarianceRed"] || 1) * 255; locStartColorVar.g = parseFloat(dict["startColorVarianceGreen"] || 1) * 255; locStartColorVar.b = parseFloat(dict["startColorVarianceBlue"] || 1) * 255; locStartColorVar.a = parseFloat(dict["startColorVarianceAlpha"] || 1) * 255; - var locEndColor = this.endColor; + var locEndColor = this._endColor; locEndColor.r = parseFloat(dict["finishColorRed"] || 1) * 255; locEndColor.g = parseFloat(dict["finishColorGreen"] || 1) * 255; locEndColor.b = parseFloat(dict["finishColorBlue"] || 1) * 255; locEndColor.a = parseFloat(dict["finishColorAlpha"] || 1) * 255; - var locEndColorVar = this.endColorVar; + var locEndColorVar = this._endColorVar; locEndColorVar.r = parseFloat(dict["finishColorVarianceRed"] || 1) * 255; locEndColorVar.g = parseFloat(dict["finishColorVarianceGreen"] || 1) * 255; locEndColorVar.b = parseFloat(dict["finishColorVarianceBlue"] || 1) * 255; From e92c36593e9afefc66f884d17d5350e384daadb8 Mon Sep 17 00:00:00 2001 From: Knox Date: Wed, 15 Aug 2018 13:51:43 +0800 Subject: [PATCH 04/53] fix layout grid bug for fireball/issues/8166 (#3093) --- cocos2d/core/components/CCLayout.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos2d/core/components/CCLayout.js b/cocos2d/core/components/CCLayout.js index 0738666906..c54cbec215 100644 --- a/cocos2d/core/components/CCLayout.js +++ b/cocos2d/core/components/CCLayout.js @@ -587,13 +587,13 @@ var Layout = cc.Class({ secondMaxHeight = childBoundingBoxHeight; tempMaxHeight = 0; } - nextX = leftBoundaryOfLayout + sign * (paddingX + anchorX * child.width); + nextX = leftBoundaryOfLayout + sign * (paddingX + anchorX * childBoundingBoxWidth); row++; } } var finalPositionY = fnPositionY(child, rowMaxHeight, row); - if (baseWidth >= (child.width + this.paddingLeft + this.paddingRight)) { + if (baseWidth >= (childBoundingBoxWidth + this.paddingLeft + this.paddingRight)) { if (applyChildren) { child.setPosition(cc.v2(nextX, finalPositionY)); } From ed724cf442aa17773c2f26260c7fdec02bf629d1 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Wed, 15 Aug 2018 16:43:05 +0800 Subject: [PATCH 05/53] Fix label blend issue when switch from ttf to bmf (#3094) --- cocos2d/core/components/CCLabel.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cocos2d/core/components/CCLabel.js b/cocos2d/core/components/CCLabel.js index 848df65585..c28283014d 100644 --- a/cocos2d/core/components/CCLabel.js +++ b/cocos2d/core/components/CCLabel.js @@ -563,6 +563,9 @@ let Label = cc.Class({ if (this._texture === this._ttfTexture) { this._srcBlendFactor = cc.macro.ONE; } + else { + this._srcBlendFactor = cc.macro.SRC_ALPHA; + } material.texture = this._texture; this._updateMaterial(material); } From d1855f26beafe566d83780313248cdf46f2fdad9 Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Wed, 15 Aug 2018 19:40:36 +0800 Subject: [PATCH 06/53] fixed graphics error (#3095) --- .../core/renderer/webgl/assemblers/graphics/impl.js | 12 +++++++++--- .../core/renderer/webgl/assemblers/graphics/index.js | 9 ++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/cocos2d/core/renderer/webgl/assemblers/graphics/impl.js b/cocos2d/core/renderer/webgl/assemblers/graphics/impl.js index 55f46942e5..f66d48931b 100644 --- a/cocos2d/core/renderer/webgl/assemblers/graphics/impl.js +++ b/cocos2d/core/renderer/webgl/assemblers/graphics/impl.js @@ -67,8 +67,6 @@ function Impl (graphics) { this._renderDatas = []; this._dataOffset = 0; - - this.requestRenderData(graphics); } cc.js.mixin(Impl.prototype, { @@ -217,7 +215,7 @@ cc.js.mixin(Impl.prototype, { pathPoints.push(pt); }, - requestRenderData (graphics) { + requestRenderData () { let renderData = new IARenderData(); let meshbuffer = new MeshBuffer(renderer._walker, vfmtPosColor); renderData.meshbuffer = meshbuffer; @@ -230,6 +228,14 @@ cc.js.mixin(Impl.prototype, { renderData.ia = ia; return renderData; + }, + + getRenderDatas () { + if (this._renderDatas.length === 0) { + this.requestRenderData(); + } + + return this._renderDatas; } }); diff --git a/cocos2d/core/renderer/webgl/assemblers/graphics/index.js b/cocos2d/core/renderer/webgl/assemblers/graphics/index.js index 8d37c49aac..2d38456598 100644 --- a/cocos2d/core/renderer/webgl/assemblers/graphics/index.js +++ b/cocos2d/core/renderer/webgl/assemblers/graphics/index.js @@ -69,7 +69,7 @@ let graphicsAssembler = { }, updateRenderData (graphics) { - let datas = graphics._impl._renderDatas; + let datas = graphics._impl.getRenderDatas(); for (let i = 0, l = datas.length; i < l; i++) { datas[i].material = graphics.getMaterial(); } @@ -94,7 +94,7 @@ let graphicsAssembler = { nodeA = nodeColor.a / 255; let impl = graphics._impl; - let renderDatas = impl._renderDatas; + let renderDatas = impl.getRenderDatas(); for (let index = 0, length = renderDatas.length; index < length; index++) { let renderData = renderDatas[index]; let meshbuffer = renderData.meshbuffer; @@ -105,7 +105,7 @@ let graphicsAssembler = { }, genRenderData (graphics, cverts) { - let renderDatas = _impl._renderDatas; + let renderDatas = _impl.getRenderDatas(); let renderData = renderDatas[_impl._dataOffset]; let meshbuffer = renderData.meshbuffer; @@ -122,6 +122,9 @@ let graphicsAssembler = { renderData = _impl.requestRenderData(graphics); renderDatas[_impl._dataOffset] = renderData; } + + renderData.material = graphics.getMaterial(); + meshbuffer = renderData.meshbuffer; } if (maxVertsCount > meshbuffer.vertexOffset) { From 2a43707cae6a77bc7194a26c8d96cc2f5e23c99b Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 16 Aug 2018 00:52:47 +0800 Subject: [PATCH 07/53] Upgrade Mask with new graphics implementation (#3096) --- cocos2d/core/components/CCMask.js | 108 ++++++++++++++---- .../webgl/assemblers/mask-assembler.js | 56 +-------- extensions/spine/Skeleton.js | 1 - 3 files changed, 87 insertions(+), 78 deletions(-) diff --git a/cocos2d/core/components/CCMask.js b/cocos2d/core/components/CCMask.js index 530dabdb8c..a242d8b3d3 100644 --- a/cocos2d/core/components/CCMask.js +++ b/cocos2d/core/components/CCMask.js @@ -30,6 +30,7 @@ const math = renderEngine.math; const StencilMaterial = renderEngine.StencilMaterial; const RenderComponent = require('./CCRenderComponent'); const RenderFlow = require('../renderer/render-flow'); +const Graphics = require('../graphics/graphics'); let _vec2_temp = cc.v2(); let _mat4_temp = math.mat4.create(); @@ -103,6 +104,7 @@ let Mask = cc.Class({ if (this._type !== MaskType.IMAGE_STENCIL) { this.spriteFrame = null; this.alphaThreshold = 0; + this._updateGraphics(); } if (this._renderData) { this.destroyRenderData(this._renderData); @@ -235,6 +237,58 @@ let Mask = cc.Class({ Type: MaskType, }, + onLoad () { + this._graphics = new Graphics(); + this._graphics.node = this.node; + this._graphics.lineWidth = 0; + }, + + onRestore () { + if (!this._graphics) { + this._graphics = new Graphics(); + this._graphics.node = this.node; + this._graphics.lineWidth = 0; + } + if (this._type !== MaskType.IMAGE_STENCIL) { + this._updateGraphics(); + } + }, + + onEnable () { + this._super(); + if (this._type !== MaskType.IMAGE_STENCIL) { + this._updateGraphics(); + } + + this.node.on(cc.Node.EventType.POSITION_CHANGED, this._updateGraphics, this); + this.node.on(cc.Node.EventType.ROTATION_CHANGED, this._updateGraphics, this); + this.node.on(cc.Node.EventType.SCALE_CHANGED, this._updateGraphics, this); + this.node.on(cc.Node.EventType.SIZE_CHANGED, this._updateGraphics, this); + this.node.on(cc.Node.EventType.ANCHOR_CHANGED, this._updateGraphics, this); + + this.node._renderFlag |= RenderFlow.FLAG_POST_RENDER | RenderFlow.FLAG_POST_UPDATE_RENDER_DATA; + this._activateMaterial(); + }, + + onDisable () { + this._super(); + + this.node.off(cc.Node.EventType.POSITION_CHANGED, this._updateGraphics, this); + this.node.off(cc.Node.EventType.ROTATION_CHANGED, this._updateGraphics, this); + this.node.off(cc.Node.EventType.SCALE_CHANGED, this._updateGraphics, this); + this.node.off(cc.Node.EventType.SIZE_CHANGED, this._updateGraphics, this); + this.node.off(cc.Node.EventType.ANCHOR_CHANGED, this._updateGraphics, this); + + this.node._renderFlag &= ~(RenderFlow.FLAG_POST_RENDER | RenderFlow.FLAG_POST_UPDATE_RENDER_DATA); + }, + + onDestroy () { + this._super(); + this._graphics.destroy(); + this._frontMaterial = null; + this._endMaterial = null; + }, + _resizeNodeToTargetNode: CC_EDITOR && function () { if(this.spriteFrame) { let rect = this.spriteFrame.getRect(); @@ -242,7 +296,7 @@ let Mask = cc.Class({ } }, - _onTextureLoaded: function (event) { + _onTextureLoaded () { // Mark render data dirty if (this._renderData) { this._renderData.uvDirty = true; @@ -255,7 +309,7 @@ let Mask = cc.Class({ } }, - _applySpriteFrame: function (oldFrame) { + _applySpriteFrame (oldFrame) { if (oldFrame && oldFrame.off) { oldFrame.off('load', this._onTextureLoaded, this); } @@ -271,7 +325,7 @@ let Mask = cc.Class({ } }, - _activateMaterial: function () { + _activateMaterial () { // cannot be activated if texture not loaded yet if (this._type === MaskType.IMAGE_STENCIL && (!this.spriteFrame || !this.spriteFrame.textureLoaded())) { this.markForRender(false); @@ -289,18 +343,22 @@ let Mask = cc.Class({ // Reset material if (this._type === MaskType.IMAGE_STENCIL) { let texture = this.spriteFrame.getTexture(); + this._frontMaterial.useModel = false; this._frontMaterial.useTexture = true; this._frontMaterial.useColor = true; this._frontMaterial.texture = texture; this._frontMaterial.alphaThreshold = this.alphaThreshold; + this._endMaterial.useModel = false; this._endMaterial.useTexture = true; this._endMaterial.useColor = true; this._endMaterial.texture = texture; this._endMaterial.alphaThreshold = this.alphaThreshold; } else { + this._frontMaterial.useModel = true; this._frontMaterial.useTexture = false; this._frontMaterial.useColor = false; + this._endMaterial.useModel = true; this._endMaterial.useTexture = false; this._endMaterial.useColor = false; } @@ -316,7 +374,29 @@ let Mask = cc.Class({ this.markForRender(true); }, - _hitTest: function (cameraPt) { + _updateGraphics () { + let node = this.node; + let graphics = this._graphics; + // Share render data with graphics content + graphics.clear(false); + let width = node._contentSize.width; + let height = node._contentSize.height; + let x = -width * node._anchorPoint.x; + let y = -height * node._anchorPoint.y; + if (this._type === MaskType.RECT) { + graphics.rect(x, y, width, height); + } + else if (this._type === MaskType.ELLIPSE) { + let cx = x + width / 2, + cy = y + height / 2, + rx = width / 2, + ry = height / 2; + graphics.ellipse(cx, cy, rx, ry); + } + graphics.fill(); + }, + + _hitTest (cameraPt) { let node = this.node; let size = node.getContentSize(), w = size.width, @@ -362,26 +442,6 @@ let Mask = cc.Class({ this.node._renderFlag &= ~(RenderFlow.FLAG_RENDER | RenderFlow.FLAG_UPDATE_RENDER_DATA | RenderFlow.FLAG_POST_RENDER | RenderFlow.FLAG_POST_UPDATE_RENDER_DATA); }, - - onEnable () { - this._super(); - // for graphic stencil data - this._graphics = null; - - this.node._renderFlag |= RenderFlow.FLAG_POST_RENDER | RenderFlow.FLAG_POST_UPDATE_RENDER_DATA; - this._activateMaterial(); - }, - - onDisable () { - this._super(); - this.node._renderFlag &= ~(RenderFlow.FLAG_POST_RENDER | RenderFlow.FLAG_POST_UPDATE_RENDER_DATA); - }, - - onDestroy () { - this._super(); - this._frontMaterial = null; - this._endMaterial = null; - }, }); cc.Mask = module.exports = Mask; diff --git a/cocos2d/core/renderer/webgl/assemblers/mask-assembler.js b/cocos2d/core/renderer/webgl/assemblers/mask-assembler.js index 7393dadaec..2d2a848836 100644 --- a/cocos2d/core/renderer/webgl/assemblers/mask-assembler.js +++ b/cocos2d/core/renderer/webgl/assemblers/mask-assembler.js @@ -24,52 +24,15 @@ ****************************************************************************/ const StencilManager = require('../stencil-manager'); -const Node = require('../../../CCNode'); const Mask = require('../../../components/CCMask'); const RenderFlow = require('../../render-flow'); const spriteAssembler = require('./sprite/simple'); -const Graphics = require('../../../graphics/graphics'); const graphicsAssembler = require('./graphics'); let _stencilMgr = StencilManager.sharedManager; -// for nested mask, we might need multiple graphics component to avoid data conflict -let _graphicsPool = []; - -function getGraphics () { - let graphics = _graphicsPool.pop(); - - if (!graphics) { - let graphicsNode = new Node(); - graphics = graphicsNode.addComponent(Graphics); - graphics.lineWidth = 0; - } - return graphics; -} let maskFrontAssembler = { - updateGraphics (mask) { - let renderData = mask._renderData; - let graphics = mask._graphics; - // Share render data with graphics content - graphics.clear(false); - let width = renderData._width; - let height = renderData._height; - let x = -width * renderData._pivotX; - let y = -height * renderData._pivotY; - if (mask._type === Mask.Type.RECT) { - graphics.rect(x, y, width, height); - } - else if (mask._type === Mask.Type.ELLIPSE) { - let cx = x + width / 2, - cy = y + height / 2, - rx = width / 2, - ry = height / 2; - graphics.ellipse(cx, cy, rx, ry); - } - graphics.fill(); - }, - updateRenderData (mask) { if (!mask._renderData) { if (mask._type === Mask.Type.IMAGE_STENCIL) { @@ -81,14 +44,13 @@ let maskFrontAssembler = { } } let renderData = mask._renderData; - let size = mask.node._contentSize; - let anchor = mask.node._anchorPoint; - renderData.updateSizeNPivot(size.width, size.height, anchor.x, anchor.y); mask._material = mask._frontMaterial; if (mask._type === Mask.Type.IMAGE_STENCIL) { - mask._material.useModel = false; if (mask.spriteFrame) { + let size = mask.node._contentSize; + let anchor = mask.node._anchorPoint; + renderData.updateSizeNPivot(size.width, size.height, anchor.x, anchor.y); renderData.dataLength = 4; spriteAssembler.updateRenderData(mask); renderData.material = mask.getMaterial(); @@ -98,9 +60,6 @@ let maskFrontAssembler = { } } else { - mask._material.useModel = true; - mask._graphics = getGraphics(); - this.updateGraphics(mask); mask._graphics._material = mask._material; graphicsAssembler.updateRenderData(mask._graphics); } @@ -117,8 +76,6 @@ let maskFrontAssembler = { spriteAssembler.fillBuffers(mask, renderer); } else { - // Share node for correct global matrix - mask._graphics.node = mask.node; graphicsAssembler.fillBuffers(mask._graphics, renderer); } } @@ -138,12 +95,10 @@ let maskEndAssembler = { let material = mask._material; if (mask._type === Mask.Type.IMAGE_STENCIL) { - material.useModel = false; let data = mask._renderData; data.material = material; } else { - material.useModel = true; let datas = mask._graphics._impl._renderDatas; for (let i = 0; i < datas.length; i++) { datas[i].material = material; @@ -162,12 +117,7 @@ let maskEndAssembler = { spriteAssembler.fillBuffers(mask, renderer); } else { - // Share node for correct global matrix - mask._graphics.node = mask.node; graphicsAssembler.fillBuffers(mask._graphics, renderer); - // put back graphics to pool - _graphicsPool.push(mask._graphics); - mask._graphics = null; } } diff --git a/extensions/spine/Skeleton.js b/extensions/spine/Skeleton.js index 7b6ecec09e..a2499d1833 100644 --- a/extensions/spine/Skeleton.js +++ b/extensions/spine/Skeleton.js @@ -28,7 +28,6 @@ const TrackEntryListeners = require('./track-entry-listeners'); const RenderComponent = require('../../cocos2d/core/components/CCRenderComponent'); const spine = require('./lib/spine'); const SpriteMaterial = require('../../cocos2d/core/renderer/render-engine').SpriteMaterial; -const Node = require('../../cocos2d/core/CCNode'); const Graphics = require('../../cocos2d/core/graphics/graphics'); /** From 328ca0fea77a71b459d6d4b8961c1623cd7737f7 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 16 Aug 2018 14:13:38 +0800 Subject: [PATCH 08/53] Support skeleton debug draw in release mode (#3099) --- extensions/spine/Skeleton.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/extensions/spine/Skeleton.js b/extensions/spine/Skeleton.js index a2499d1833..9eb84aff80 100644 --- a/extensions/spine/Skeleton.js +++ b/extensions/spine/Skeleton.js @@ -326,9 +326,7 @@ sp.Skeleton = cc.Class({ this._material = new SpriteMaterial(); this._renderDatas = []; - if (CC_DEBUG) { - this._debugRenderer = null; - } + this._debugRenderer = null; }, /** @@ -917,7 +915,7 @@ sp.Skeleton = cc.Class({ Editor.Utils.refreshSelectedInspector('node', this.node.uuid); }, - _initDebugDraw: CC_DEBUG && function () { + _initDebugDraw: function () { if (this.debugBones || this.debugSlots) { if (!this._debugRenderer) { let debugDrawNode = new cc.PrivateNode(); From 4cb859e7a2f6a01011969673d534ff6202ab921b Mon Sep 17 00:00:00 2001 From: Knox Date: Thu, 16 Aug 2018 14:17:23 +0800 Subject: [PATCH 09/53] add PNGReader and tiffReader to ParticleSystem static (#3100) --- cocos2d/particle/CCParticleSystem.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cocos2d/particle/CCParticleSystem.js b/cocos2d/particle/CCParticleSystem.js index 98946b8ed6..a8c50cf9b5 100644 --- a/cocos2d/particle/CCParticleSystem.js +++ b/cocos2d/particle/CCParticleSystem.js @@ -756,6 +756,10 @@ var ParticleSystem = cc.Class({ EmitterMode: EmitterMode, PositionType: PositionType, + + + _PNGReader: PNGReader, + _TIFFReader: tiffReader, }, // EDITOR RELATED METHODS @@ -1165,3 +1169,4 @@ var ParticleSystem = cc.Class({ }); cc.ParticleSystem = module.exports = ParticleSystem; + From 77678d219ade5117c5b85119916464ecd9ee5123 Mon Sep 17 00:00:00 2001 From: PP Date: Thu, 16 Aug 2018 16:51:48 +0800 Subject: [PATCH 10/53] improve audio state control (#3102) --- cocos2d/audio/CCAudio.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cocos2d/audio/CCAudio.js b/cocos2d/audio/CCAudio.js index b274ff008a..918815cdca 100644 --- a/cocos2d/audio/CCAudio.js +++ b/cocos2d/audio/CCAudio.js @@ -77,7 +77,11 @@ Audio.State = { /** * @property {Number} PAUSED */ - PAUSED: 2 + PAUSED: 2, + /** + * @property {Number} STOPPED + */ + STOPPED: 3, }; (function (proto) { @@ -171,14 +175,14 @@ Audio.State = { }; proto.pause = function () { - if (!this._element) return; + if (!this._element || this._state !== Audio.State.PLAYING) return; this._unbindEnded(); this._element.pause(); this._state = Audio.State.PAUSED; }; proto.resume = function () { - if (!this._element || this._state === Audio.State.PLAYING) return; + if (!this._element || this._state !== Audio.State.PAUSED) return; this._bindEnded(); this._element.play(); this._state = Audio.State.PLAYING; @@ -199,7 +203,7 @@ Audio.State = { } this._unbindEnded(); this.emit('stop'); - this._state = Audio.State.PAUSED; + this._state = Audio.State.STOPPED; }; proto.setLoop = function (loop) { From 790020397f3c491577a201934c222fcb75d9be13 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 16 Aug 2018 22:30:47 +0800 Subject: [PATCH 11/53] Fix Mask module dependency (#3106) --- modules.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules.json b/modules.json index 10fa77d594..0b831ccf82 100644 --- a/modules.json +++ b/modules.json @@ -67,7 +67,8 @@ "./cocos2d/core/components/CCMask.js", "./cocos2d/core/renderer/webgl/assemblers/mask-assembler.js", "./cocos2d/core/renderer/canvas/renderers/mask.js" - ] + ], + "dependencies": ["Graphics"] }, { "name": "Graphics", From ada1d1335c5606540d8e4e055b866793ab4caa78 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 16 Aug 2018 22:39:11 +0800 Subject: [PATCH 12/53] Fix switch index buffer from released customIA issue (#3107) --- cocos2d/core/renderer/render-engine.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cocos2d/core/renderer/render-engine.js b/cocos2d/core/renderer/render-engine.js index 7d3e96bd68..8fb21167ee 100644 --- a/cocos2d/core/renderer/render-engine.js +++ b/cocos2d/core/renderer/render-engine.js @@ -9642,7 +9642,12 @@ Device.prototype._restoreIndexBuffer = function _restoreIndexBuffer () { var gl = this._gl; var ib = this._current.indexBuffer; - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, ib ? ib._glID : null); + if (ib && ib._glID !== -1) { + gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, ib._glID); + } + else { + gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null); + } }; /** From 7490c5de5c16063e8e99de6697cc37d061c352d4 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 16 Aug 2018 22:45:00 +0800 Subject: [PATCH 13/53] Fix tmx object group x, y parse issue (#3108) --- cocos2d/core/components/CCSprite.js | 2 +- cocos2d/tilemap/CCTMXXMLParser.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cocos2d/core/components/CCSprite.js b/cocos2d/core/components/CCSprite.js index dba2ddea99..17c4f5d012 100644 --- a/cocos2d/core/components/CCSprite.js +++ b/cocos2d/core/components/CCSprite.js @@ -582,7 +582,7 @@ var Sprite = cc.Class({ } }, - _onTextureLoaded: function (event) { + _onTextureLoaded: function () { if (!this.isValid) { return; } diff --git a/cocos2d/tilemap/CCTMXXMLParser.js b/cocos2d/tilemap/CCTMXXMLParser.js index d473e19919..163516440d 100644 --- a/cocos2d/tilemap/CCTMXXMLParser.js +++ b/cocos2d/tilemap/CCTMXXMLParser.js @@ -867,8 +867,8 @@ cc.TMXMapInfo.prototype = { objectProp["width"] = parseFloat(selObj.getAttribute('width')) || 0; objectProp["height"] = parseFloat(selObj.getAttribute('height')) || 0; - objectProp["x"] = (selObj.getAttribute('x') || 0); - objectProp["y"] = (selObj.getAttribute('y') || 0); + objectProp["x"] = parseFloat(selObj.getAttribute('x')) || 0; + objectProp["y"] = parseFloat(selObj.getAttribute('y')) || 0; objectProp["rotation"] = parseFloat(selObj.getAttribute('rotation')) || 0; From 5cad94340b461115444b9bb4749660bb83ada92a Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 16 Aug 2018 22:53:45 +0800 Subject: [PATCH 14/53] Support stencil & depth buffer in render texture (#3109) --- cocos2d/core/assets/CCRenderTexture.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/cocos2d/core/assets/CCRenderTexture.js b/cocos2d/core/assets/CCRenderTexture.js index 28e444b955..856bce29bf 100644 --- a/cocos2d/core/assets/CCRenderTexture.js +++ b/cocos2d/core/assets/CCRenderTexture.js @@ -1,5 +1,6 @@ const renderer = require('../renderer'); const renderEngine = require('../renderer/render-engine'); +const gfx = renderEngine.gfx; const Texture2D = require('./CCTexture2D'); /** @@ -24,7 +25,7 @@ let RenderTexture = cc.Class({ * @param {Number} [height] * @method initWithSize */ - initWithSize (width, height) { + initWithSize (width, height, depthStencilFormat) { this.width = Math.floor(width || cc.visibleRect.width); this.height = Math.floor(height || cc.visibleRect.height); @@ -44,8 +45,20 @@ let RenderTexture = cc.Class({ } opts = { - colors: [ this._texture ] + colors: [ this._texture ], }; + if (depthStencilFormat) { + let depthStencilBuffer = new gfx.RenderBuffer(renderer.device, depthStencilFormat, width, height); + if (depthStencilFormat === gfx.RB_FMT_D24S8) { + opts.depth = opts.stencil = depthStencilBuffer; + } + else if (depthStencilFormat === gfx.RB_FMT_S8) { + opts.stencil = depthStencilBuffer; + } + else if (depthStencilFormat === gl.RB_FMT_D16) { + opts.depth = depthStencilBuffer; + } + } if (this._framebuffer) { this._framebuffer.destroy(); From 4c3ed282174c601d4c8519fc530a373d5bda44c6 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 16 Aug 2018 23:42:12 +0800 Subject: [PATCH 15/53] Fix color channel value overflow issue (#3110) --- cocos2d/core/value-types/color.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cocos2d/core/value-types/color.js b/cocos2d/core/value-types/color.js index d3367527e0..5375baf18e 100644 --- a/cocos2d/core/value-types/color.js +++ b/cocos2d/core/value-types/color.js @@ -263,7 +263,8 @@ var Color = (function () { * color.setR(255); // Color {r: 255, g: 0, b: 0, a: 255} */ proto.setR = function (red) { - this._val = ((this._val & 0xffffff00) | ~~red) >>> 0; + red = ~~cc.misc.clampf(red, 0, 255); + this._val = ((this._val & 0xffffff00) | red) >>> 0; return this; }; /** @@ -286,7 +287,8 @@ var Color = (function () { * color.setG(255); // Color {r: 0, g: 255, b: 0, a: 255} */ proto.setG = function (green) { - this._val = ((this._val & 0xffff00ff) | (~~green << 8)) >>> 0; + green = ~~cc.misc.clampf(green, 0, 255); + this._val = ((this._val & 0xffff00ff) | (green << 8)) >>> 0; return this; }; /** @@ -309,7 +311,8 @@ var Color = (function () { * color.setB(255); // Color {r: 0, g: 0, b: 255, a: 255} */ proto.setB = function (blue) { - this._val = ((this._val & 0xff00ffff) | (~~blue << 16)) >>> 0; + blue = ~~cc.misc.clampf(blue, 0, 255); + this._val = ((this._val & 0xff00ffff) | (blue << 16)) >>> 0; return this; }; /** @@ -332,7 +335,8 @@ var Color = (function () { * color.setA(0); // Color {r: 0, g: 0, b: 0, a: 0} */ proto.setA = function (alpha) { - this._val = ((this._val & 0x00ffffff) | ((~~alpha << 24) >>> 0)) >>> 0; + alpha = ~~cc.misc.clampf(alpha, 0, 255); + this._val = ((this._val & 0x00ffffff) | ((alpha << 24) >>> 0)) >>> 0; return this; }; From acab0756f06c2354ea2270a9f561b70391d7b8c5 Mon Sep 17 00:00:00 2001 From: ColinCollins <35832931+ColinCollins@users.noreply.github.com> Date: Fri, 17 Aug 2018 10:15:03 +0800 Subject: [PATCH 16/53] modify the scrollView boundary calculate listener event (#3104) * fixed the widget make the content position offset * fixed the widget make the content position offset * modify the scrollView Component, adjust the boundary size. --- cocos2d/core/components/CCScrollView.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/cocos2d/core/components/CCScrollView.js b/cocos2d/core/components/CCScrollView.js index 1b19ac0211..1f6112c31c 100644 --- a/cocos2d/core/components/CCScrollView.js +++ b/cocos2d/core/components/CCScrollView.js @@ -887,26 +887,26 @@ let ScrollView = cc.Class({ if(layout && layout.enabledInHierarchy) { layout.updateLayout(); } - let scrollViewSize = this.node.getContentSize(); + let viewSize = this.content.parent.getContentSize(); let leftBottomPosition = this._convertToContentParentSpace(cc.v2(0, 0)); this._leftBoundary = leftBottomPosition.x; this._bottomBoundary = leftBottomPosition.y; - let topRightPosition = this._convertToContentParentSpace(cc.v2(scrollViewSize.width, scrollViewSize.height)); + let topRightPosition = this._convertToContentParentSpace(viewSize); this._rightBoundary = topRightPosition.x; this._topBoundary = topRightPosition.y; if (!CC_EDITOR) { - this._moveContentToTopLeft(scrollViewSize); + this._moveContentToTopLeft(viewSize); } } }, _convertToContentParentSpace (position) { - let scrollViewPositionInWorldSpace = this.node.convertToWorldSpace(position); let contentParent = this.content.parent; - return contentParent.convertToNodeSpaceAR(scrollViewPositionInWorldSpace); + let viewPositionInWorldSpace = contentParent.convertToWorldSpace(position); + return contentParent.convertToNodeSpaceAR(viewPositionInWorldSpace); }, //this is for nested scrollview @@ -1517,6 +1517,11 @@ let ScrollView = cc.Class({ if (this.content) { this.content.off(NodeEvent.SIZE_CHANGED, this._calculateBoundary, this); this.content.off(NodeEvent.SCALE_CHANGED, this._calculateBoundary, this); + if (this.content.parent) { + this.content.parent.off(NodeEvent.POSITION_CHANGED, this._calculateBoundary, this); + this.content.parent.off(NodeEvent.SCALE_CHANGED, this._calculateBoundary, this); + this.content.parent.off(NodeEvent.SIZE_CHANGED, this._calculateBoundary, this); + } } } this._hideScrollbar(); @@ -1531,6 +1536,11 @@ let ScrollView = cc.Class({ if (this.content) { this.content.on(NodeEvent.SIZE_CHANGED, this._calculateBoundary, this); this.content.on(NodeEvent.SCALE_CHANGED, this._calculateBoundary, this); + if (this.content.parent) { + this.content.parent.on(NodeEvent.POSITION_CHANGED, this._calculateBoundary, this); + this.content.parent.on(NodeEvent.SCALE_CHANGED, this._calculateBoundary, this); + this.content.parent.on(NodeEvent.SIZE_CHANGED, this._calculateBoundary, this); + } } } this._showScrollbar(); From f2b815b8dac1723db7191e21ace4f92314866d6f Mon Sep 17 00:00:00 2001 From: pandamicro Date: Sun, 19 Aug 2018 13:31:49 +0800 Subject: [PATCH 17/53] Upgrade Mask canvas renderer (#3115) * Upgrade Mask canvas renderer * Improve sub context view rendering --- cocos2d/core/components/CCMask.js | 8 +++- cocos2d/core/components/WXSubContextView.js | 2 + .../core/renderer/canvas/renderers/mask.js | 40 ------------------- 3 files changed, 9 insertions(+), 41 deletions(-) diff --git a/cocos2d/core/components/CCMask.js b/cocos2d/core/components/CCMask.js index a242d8b3d3..f20ef0fba2 100644 --- a/cocos2d/core/components/CCMask.js +++ b/cocos2d/core/components/CCMask.js @@ -241,6 +241,7 @@ let Mask = cc.Class({ this._graphics = new Graphics(); this._graphics.node = this.node; this._graphics.lineWidth = 0; + this._graphics.strokeColor = cc.color(0, 0, 0, 0); }, onRestore () { @@ -393,7 +394,12 @@ let Mask = cc.Class({ ry = height / 2; graphics.ellipse(cx, cy, rx, ry); } - graphics.fill(); + if (cc.game.renderType === cc.game.RENDER_TYPE_CANVAS) { + graphics.stroke(); + } + else { + graphics.fill(); + } }, _hitTest (cameraPt) { diff --git a/cocos2d/core/components/WXSubContextView.js b/cocos2d/core/components/WXSubContextView.js index ea22559628..5b313410c9 100644 --- a/cocos2d/core/components/WXSubContextView.js +++ b/cocos2d/core/components/WXSubContextView.js @@ -82,11 +82,13 @@ else { sharedCanvas.width = this.node.width; sharedCanvas.height = this.node.height; } + this._tex.setPremultiplyAlpha(true); this._tex.initWithElement(sharedCanvas); this._sprite = this.node.getComponent(cc.Sprite); if (!this._sprite) { this._sprite = this.node.addComponent(cc.Sprite); + this._sprite.srcBlendFactor = cc.macro.BlendFactor.ONE; } this._sprite.spriteFrame = new cc.SpriteFrame(this._tex); } diff --git a/cocos2d/core/renderer/canvas/renderers/mask.js b/cocos2d/core/renderer/canvas/renderers/mask.js index 0d368a867f..80c10f533b 100644 --- a/cocos2d/core/renderer/canvas/renderers/mask.js +++ b/cocos2d/core/renderer/canvas/renderers/mask.js @@ -23,48 +23,11 @@ THE SOFTWARE. ****************************************************************************/ -const Node = require('../../../CCNode'); const Mask = require('../../../components/CCMask'); -const Graphics = require('../../../graphics/graphics'); const graphicsHandler = require('./graphics'); -// for nested mask, we might need multiple graphics component to avoid data conflict -let _graphicsPool = []; - -function getGraphics () { - let graphics = _graphicsPool.pop(); - - if (!graphics) { - let graphicsNode = new Node(); - graphics = graphicsNode.addComponent(Graphics); - graphics.lineWidth = 0; - } - return graphics; -} - let beforeHandler = { updateRenderData (comp) {}, - updateGraphics (mask) { - let node = mask.node; - let graphics = mask._graphics; - // Share render data with graphics content - graphics.clear(false); - let width = node.width; - let height = node.height; - let x = -width * node.anchorX; - let y = -height * node.anchorY; - if (mask._type === Mask.Type.RECT) { - graphics.rect(x, y, width, height); - } - else if (mask._type === Mask.Type.ELLIPSE) { - let cx = x + width / 2, - cy = y + height / 2, - rx = width / 2, - ry = height / 2; - graphics.ellipse(cx, cy, rx, ry); - } - graphics.stroke(); - }, draw (ctx, mask) { let node = mask.node; @@ -74,11 +37,8 @@ let beforeHandler = { tx = matrix.m12, ty = matrix.m13; ctx.save(); - ctx.transform(a, b, c, d, tx, -ty); // draw stencil - mask._graphics = getGraphics(); - this.updateGraphics(mask); graphicsHandler.draw(ctx, mask._graphics); ctx.clip(); From 19c095a30108d413c67fb9b51e66ebf1274f0667 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Sun, 19 Aug 2018 14:25:14 +0800 Subject: [PATCH 18/53] Fix Label flurry and dirty border issue (#3116) --- cocos2d/core/components/CCLabel.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cocos2d/core/components/CCLabel.js b/cocos2d/core/components/CCLabel.js index c28283014d..b97d230e2c 100644 --- a/cocos2d/core/components/CCLabel.js +++ b/cocos2d/core/components/CCLabel.js @@ -543,7 +543,6 @@ let Label = cc.Class({ else { if (!this._ttfTexture) { this._ttfTexture = new cc.Texture2D(); - this._ttfTexture.setPremultiplyAlpha(true); this._assemblerData = this._assembler._getAssemblerData(); this._ttfTexture.initWithElement(this._assemblerData.canvas); } @@ -561,10 +560,10 @@ let Label = cc.Class({ } // Setup blend function for premultiplied ttf label texture if (this._texture === this._ttfTexture) { - this._srcBlendFactor = cc.macro.ONE; + this._srcBlendFactor = cc.macro.BlendFactor.ONE; } else { - this._srcBlendFactor = cc.macro.SRC_ALPHA; + this._srcBlendFactor = cc.macro.BlendFactor.SRC_ALPHA; } material.texture = this._texture; this._updateMaterial(material); From 87d8dda5559a7b23768362f900284c4f19479389 Mon Sep 17 00:00:00 2001 From: ColinCollins <35832931+ColinCollins@users.noreply.github.com> Date: Sun, 19 Aug 2018 17:21:12 +0800 Subject: [PATCH 19/53] Scroll view2.0 (#3114) * modify rect.js create.d.ts * fixed the scrollView --- cocos2d/core/components/CCScrollView.js | 2 +- cocos2d/core/value-types/rect.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cocos2d/core/components/CCScrollView.js b/cocos2d/core/components/CCScrollView.js index 1f6112c31c..a48be27fab 100644 --- a/cocos2d/core/components/CCScrollView.js +++ b/cocos2d/core/components/CCScrollView.js @@ -893,7 +893,7 @@ let ScrollView = cc.Class({ this._leftBoundary = leftBottomPosition.x; this._bottomBoundary = leftBottomPosition.y; - let topRightPosition = this._convertToContentParentSpace(viewSize); + let topRightPosition = this._convertToContentParentSpace(cc.v2(viewSize.width, viewSize.height)); this._rightBoundary = topRightPosition.x; this._topBoundary = topRightPosition.y; diff --git a/cocos2d/core/value-types/rect.js b/cocos2d/core/value-types/rect.js index 4c620973c6..3c014b8497 100644 --- a/cocos2d/core/value-types/rect.js +++ b/cocos2d/core/value-types/rect.js @@ -171,7 +171,7 @@ proto.set = function (source) { * !#zh 当前矩形与指定矩形是否相交。 * @method intersects * @param {Rect} rect - * @type {Boolean} + * @return {Boolean} * @example * var a = new cc.Rect(0, 0, 10, 10); * var b = new cc.Rect(0, 0, 20, 20); @@ -214,7 +214,7 @@ proto.intersection = function (out, rectB) { * Returns true if the point inside this rectangle. * @method contains * @param {Vec2} point - * @type {Boolean} + * @return {Boolean} * @example * var a = new cc.Rect(0, 0, 10, 10); * var b = new cc.Vec2(0, 5); @@ -232,7 +232,7 @@ proto.contains = function (point) { * !#zh 当前矩形是否包含指定矩形。 * @method containsRect * @param {Rect} rect - * @type {Boolean} + * @return {Boolean} * @example * var a = new cc.Rect(0, 0, 20, 20); * var b = new cc.Rect(0, 0, 10, 10); From 438f7e73f6139266ebe372919270a117d11f7abd Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Mon, 20 Aug 2018 10:51:47 +0800 Subject: [PATCH 20/53] fixed tmx object group (#3113) * fixed tmx object group * refine code --- cocos2d/tilemap/CCTiledObjectGroup.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cocos2d/tilemap/CCTiledObjectGroup.js b/cocos2d/tilemap/CCTiledObjectGroup.js index 7f90375cec..bf472342c3 100644 --- a/cocos2d/tilemap/CCTiledObjectGroup.js +++ b/cocos2d/tilemap/CCTiledObjectGroup.js @@ -142,13 +142,12 @@ let TiledObjectGroup = cc.Class({ let objects = groupInfo._objects; for (let i = 0, l = objects.length; i < l; i++) { let object = objects[i]; + object.offset = cc.v2(object.x, object.y); if (cc.TiledMap.Orientation.ISO !== this._mapOrientation) { object.y = height - object.y; } else { - let mapSize = mapInfo.getMapSize(); - let tileSize = mapInfo.getTileSize(); - let posIdxX = (this._container.offset.x + offset.x) / tileSize.width * 2; - let posIdxY = (this._container.offset.y + offset.y) / tileSize.height; + let posIdxX = object.offset.x / tileSize.width * 2; + let posIdxY = object.offset.y / tileSize.height; object.x = tileSize.width / 2 * (mapSize.width + posIdxX - posIdxY); object.y = tileSize.height / 2 * (mapSize.height * 2 - posIdxX - posIdxY); } From 27f50124752fe7ecc71441b95359527b8bb3ba0d Mon Sep 17 00:00:00 2001 From: pandamicro Date: Mon, 20 Aug 2018 15:56:47 +0800 Subject: [PATCH 21/53] Fix label rendering artifact on web (#3117) --- cocos2d/core/components/CCLabel.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cocos2d/core/components/CCLabel.js b/cocos2d/core/components/CCLabel.js index b97d230e2c..2fe08e88a3 100644 --- a/cocos2d/core/components/CCLabel.js +++ b/cocos2d/core/components/CCLabel.js @@ -543,6 +543,10 @@ let Label = cc.Class({ else { if (!this._ttfTexture) { this._ttfTexture = new cc.Texture2D(); + // TTF texture in web will blend with canvas or body background color + if (!CC_JSB) { + this._ttfTexture.setPremultiplyAlpha(true); + } this._assemblerData = this._assembler._getAssemblerData(); this._ttfTexture.initWithElement(this._assemblerData.canvas); } From ffc98f9fb2fe13911ae2f20f2cf2ef261e54c02b Mon Sep 17 00:00:00 2001 From: pandamicro Date: Mon, 20 Aug 2018 16:00:32 +0800 Subject: [PATCH 22/53] Fix spine debug draw not showing in release (#3118) --- extensions/spine/spine-assembler.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/extensions/spine/spine-assembler.js b/extensions/spine/spine-assembler.js index 3236870ae6..01e21c6ec1 100644 --- a/extensions/spine/spine-assembler.js +++ b/extensions/spine/spine-assembler.js @@ -124,7 +124,7 @@ var spineAssembler = { dataOffset++; } - if (CC_DEBUG && comp.debugSlots && vertexCount === 4) { + if (comp.debugSlots && vertexCount === 4) { let graphics = comp._debugRenderer; // Debug Slot @@ -147,7 +147,7 @@ var spineAssembler = { let premultiAlpha = comp.premultipliedAlpha; let graphics = comp._debugRenderer; - if (CC_DEBUG && comp.debugBones || comp.debugSlots) { + if (comp.debugBones || comp.debugSlots) { graphics.clear(); } @@ -254,7 +254,7 @@ var spineAssembler = { datas.length = dataId; } - if (CC_DEBUG && comp.debugBones) { + if (comp.debugBones) { let bone; graphics.lineWidth = 5; graphics.strokeColor = _boneColor; From 0e8b4ec3e1ed6e842d467484be90507351dae201 Mon Sep 17 00:00:00 2001 From: Knox Date: Mon, 20 Aug 2018 18:34:50 +0800 Subject: [PATCH 23/53] fix setFinishCallback bug for fireball/issues/8217 (#3119) --- cocos2d/audio/CCAudioEngine.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cocos2d/audio/CCAudioEngine.js b/cocos2d/audio/CCAudioEngine.js index 17f47d4632..14d8026894 100644 --- a/cocos2d/audio/CCAudioEngine.js +++ b/cocos2d/audio/CCAudioEngine.js @@ -44,7 +44,7 @@ let recycleAudio = function (audio) { else { audio.destroy(); } -} +}; let getAudioFromPath = function (path) { var id = _instanceId++; @@ -61,6 +61,10 @@ let getAudioFromPath = function (path) { var audio = _audioPool.pop() || new Audio(); var callback = function () { + if (audio._finishCallback) { + audio._finishCallback(); + } + var audioInList = getAudioFromId(this.id); if (audioInList) { delete _id2audio[this.id]; @@ -289,10 +293,7 @@ var audioEngine = { var audio = getAudioFromId(audioID); if (!audio) return; - audio.off('ended', audio._finishCallback); - audio._finishCallback = callback; - audio.on('ended', audio._finishCallback); }, /** From 7c7f3d4e3ad27769f1fe18d1285448f4baa6130f Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 20 Aug 2018 18:38:06 +0800 Subject: [PATCH 24/53] cc.Audio.stop logic fix, pause should be invoked before set currentTime = 0 (#3121) --- cocos2d/audio/CCAudio.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/audio/CCAudio.js b/cocos2d/audio/CCAudio.js index 918815cdca..568120454c 100644 --- a/cocos2d/audio/CCAudio.js +++ b/cocos2d/audio/CCAudio.js @@ -190,10 +190,10 @@ Audio.State = { proto.stop = function () { if (!this._element) return; + this._element.pause(); try { this._element.currentTime = 0; } catch (error) {} - this._element.pause(); // remove touchPlayList for (let i = 0; i < touchPlayList.length; i++) { if (touchPlayList[i].instance === this) { From a8a84dd9fa46a4257ae825d9a2ef69c36620746c Mon Sep 17 00:00:00 2001 From: pandamicro Date: Mon, 20 Aug 2018 19:09:45 +0800 Subject: [PATCH 25/53] Fix Particle plist parsing issues (#3122) * Support absent textureFile in particle plist * Fix particle parse issue when color channel value equals to zero --- cocos2d/core/utils/texture-util.js | 2 +- cocos2d/particle/CCParticleSystem.js | 44 ++++++++++++++++------------ 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/cocos2d/core/utils/texture-util.js b/cocos2d/core/utils/texture-util.js index a90fb23f84..a5bd5916ca 100644 --- a/cocos2d/core/utils/texture-util.js +++ b/cocos2d/core/utils/texture-util.js @@ -57,7 +57,7 @@ let textureUtil = { return cb && cb.call(target, err || new Error('Unknown error')); } texture.handleLoadedTexture(); - cb && cb.call(target, texture); + cb && cb.call(target, null, texture); }); return tex; } diff --git a/cocos2d/particle/CCParticleSystem.js b/cocos2d/particle/CCParticleSystem.js index a8c50cf9b5..c23d802f11 100644 --- a/cocos2d/particle/CCParticleSystem.js +++ b/cocos2d/particle/CCParticleSystem.js @@ -958,9 +958,15 @@ var ParticleSystem = cc.Class({ // texture if (dict["textureFileName"]) { // Try to get the texture from the cache - var tex = textureUtil.loadImage(imgPath); - // TODO: Use cc.loader to load asynchronously the SpriteFrame object, avoid using textureUtil - this.spriteFrame = new cc.SpriteFrame(tex); + textureUtil.loadImage(imgPath, function (error, texture) { + if (error) { + dict["textureFileName"] = undefined; + this._initTextureWithDictionary(dict); + } + else { + this.spriteFrame = new cc.SpriteFrame(texture); + } + }, this); } else if (dict["textureImageData"]) { var textureData = dict["textureImageData"]; @@ -1018,28 +1024,28 @@ var ParticleSystem = cc.Class({ // color var locStartColor = this._startColor; - locStartColor.r = parseFloat(dict["startColorRed"] || 1) * 255; - locStartColor.g = parseFloat(dict["startColorGreen"] || 1) * 255; - locStartColor.b = parseFloat(dict["startColorBlue"] || 1) * 255; - locStartColor.a = parseFloat(dict["startColorAlpha"] || 1) * 255; + locStartColor.r = parseFloat(dict["startColorRed"] || 0) * 255; + locStartColor.g = parseFloat(dict["startColorGreen"] || 0) * 255; + locStartColor.b = parseFloat(dict["startColorBlue"] || 0) * 255; + locStartColor.a = parseFloat(dict["startColorAlpha"] || 0) * 255; var locStartColorVar = this._startColorVar; - locStartColorVar.r = parseFloat(dict["startColorVarianceRed"] || 1) * 255; - locStartColorVar.g = parseFloat(dict["startColorVarianceGreen"] || 1) * 255; - locStartColorVar.b = parseFloat(dict["startColorVarianceBlue"] || 1) * 255; - locStartColorVar.a = parseFloat(dict["startColorVarianceAlpha"] || 1) * 255; + locStartColorVar.r = parseFloat(dict["startColorVarianceRed"] || 0) * 255; + locStartColorVar.g = parseFloat(dict["startColorVarianceGreen"] || 0) * 255; + locStartColorVar.b = parseFloat(dict["startColorVarianceBlue"] || 0) * 255; + locStartColorVar.a = parseFloat(dict["startColorVarianceAlpha"] || 0) * 255; var locEndColor = this._endColor; - locEndColor.r = parseFloat(dict["finishColorRed"] || 1) * 255; - locEndColor.g = parseFloat(dict["finishColorGreen"] || 1) * 255; - locEndColor.b = parseFloat(dict["finishColorBlue"] || 1) * 255; - locEndColor.a = parseFloat(dict["finishColorAlpha"] || 1) * 255; + locEndColor.r = parseFloat(dict["finishColorRed"] || 0) * 255; + locEndColor.g = parseFloat(dict["finishColorGreen"] || 0) * 255; + locEndColor.b = parseFloat(dict["finishColorBlue"] || 0) * 255; + locEndColor.a = parseFloat(dict["finishColorAlpha"] || 0) * 255; var locEndColorVar = this._endColorVar; - locEndColorVar.r = parseFloat(dict["finishColorVarianceRed"] || 1) * 255; - locEndColorVar.g = parseFloat(dict["finishColorVarianceGreen"] || 1) * 255; - locEndColorVar.b = parseFloat(dict["finishColorVarianceBlue"] || 1) * 255; - locEndColorVar.a = parseFloat(dict["finishColorVarianceAlpha"] || 1) * 255; + locEndColorVar.r = parseFloat(dict["finishColorVarianceRed"] || 0) * 255; + locEndColorVar.g = parseFloat(dict["finishColorVarianceGreen"] || 0) * 255; + locEndColorVar.b = parseFloat(dict["finishColorVarianceBlue"] || 0) * 255; + locEndColorVar.a = parseFloat(dict["finishColorVarianceAlpha"] || 0) * 255; // particle size this.startSize = parseFloat(dict["startParticleSize"] || 0); From 2edeb68f5247d09762f183753092f79faf7cec1f Mon Sep 17 00:00:00 2001 From: pandamicro Date: Tue, 21 Aug 2018 00:11:41 +0800 Subject: [PATCH 26/53] 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(); } From 8f55b807bd84024665c2237f4247edda0f541c1b Mon Sep 17 00:00:00 2001 From: PP Date: Tue, 21 Aug 2018 12:46:17 +0800 Subject: [PATCH 27/53] fix uninteractable transition color (#3126) --- cocos2d/core/components/CCButton.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/core/components/CCButton.js b/cocos2d/core/components/CCButton.js index 4071a015fe..b8795590ee 100644 --- a/cocos2d/core/components/CCButton.js +++ b/cocos2d/core/components/CCButton.js @@ -401,7 +401,7 @@ let Button = cc.Class({ // // Restore button status let target = this.target; let transition = this.transition; - if (transition === Transition.COLOR) { + if (transition === Transition.COLOR && this.interactable) { target.color = this.normalColor; } else if (transition === Transition.SCALE) { target.scale = this._originalScale; From 60c251a615322bc65414a8440768d7434e21f326 Mon Sep 17 00:00:00 2001 From: Knox Date: Tue, 21 Aug 2018 13:08:55 +0800 Subject: [PATCH 28/53] fix tiledmap asset is null and cannot be released (#3127) * fix tiledmap asset is null and cannot be released * refine ocde --- cocos2d/tilemap/CCTiledMap.js | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/cocos2d/tilemap/CCTiledMap.js b/cocos2d/tilemap/CCTiledMap.js index 865046a813..8e59848c65 100644 --- a/cocos2d/tilemap/CCTiledMap.js +++ b/cocos2d/tilemap/CCTiledMap.js @@ -423,12 +423,14 @@ let TiledMap = cc.Class({ return this._tileProperties[GID]; }, - onEnable () { + start () { if (this._tmxFile) { // refresh layer entities this._applyFile(); } + }, + onEnable () { this.node.on(cc.Node.EventType.ANCHOR_CHANGED, this._syncAnchorPoint, this); }, @@ -462,6 +464,24 @@ let TiledMap = cc.Class({ this._buildWithMapInfo(mapInfo); } + else { + this._relseasMapInfo() + } + }, + + _relseasMapInfo () { + // remove the layers & object groups added before + let layers = this._layers; + for (let i = 0, l = layers.length; i < l; i++) { + layers[i].node.removeFromParent(); + } + layers.length = 0; + + let groups = this._groups; + for (let i = 0, l = groups.length; i < l; i++) { + groups[i].node.removeFromParent(); + } + groups.length = 0; }, _syncAnchorPoint () { @@ -478,19 +498,10 @@ let TiledMap = cc.Class({ this._properties = mapInfo.properties; this._tileProperties = mapInfo.getTileProperties(); - // remove the layers & object groups added before + this._relseasMapInfo(); + let layers = this._layers; - for (let i = 0, l = layers.length; i < l; i++) { - layers[i].node.removeFromParent(); - } - layers.length = 0; - let groups = this._groups; - for (let i = 0, l = groups.length; i < l; i++) { - groups[i].node.removeFromParent(); - } - groups.length = 0; - let node = this.node; let layerInfos = mapInfo.getAllChildren(); if (layerInfos && layerInfos.length > 0) { From bb43d38acb0308430979dda99dc2c28ef3dd0521 Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Tue, 21 Aug 2018 15:13:04 +0800 Subject: [PATCH 29/53] support parse property type in .tmx file (#3125) --- cocos2d/tilemap/CCTMXXMLParser.js | 69 ++++++++++++++++--------------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/cocos2d/tilemap/CCTMXXMLParser.js b/cocos2d/tilemap/CCTMXXMLParser.js index 163516440d..4b497a3fbb 100644 --- a/cocos2d/tilemap/CCTMXXMLParser.js +++ b/cocos2d/tilemap/CCTMXXMLParser.js @@ -189,7 +189,7 @@ cc.TMXTilesetInfo.prototype = { } }; -function getPropertyList (node) { +function getPropertyList (node, map) { let res = []; let properties = node.getElementsByTagName("properties"); for (let i = 0; i < properties.length; ++i) { @@ -198,7 +198,36 @@ function getPropertyList (node) { res.push(property[j]); } } - return res.length ? res : null; + + map = map || {}; + for (i = 0; i < res.length; i++) { + let element = res[i]; + let name = element.getAttribute('name'); + let type = element.getAttribute('type') || 'string'; + + let value = element.getAttribute('value'); + if (type === 'int') { + value = parseInt(value); + } + else if (type === 'float') { + value = parseFloat(value); + } + else if (type === 'bool') { + value = value === 'true'; + } + else if (type === 'color') { + value = (value.indexOf('#') === 0) ? value.substring(1) : value; + let a = parseInt(value.substr(0, 2), 16) || 255; + let r = parseInt(value.substr(2, 2), 16) || 0; + let g = parseInt(value.substr(4, 2), 16) || 0; + let b = parseInt(value.substr(6, 2), 16) || 0; + value = cc.color(r, g, b, a); + } + + map[name] = value; + } + + return map; } /** @@ -624,14 +653,7 @@ cc.TMXMapInfo.prototype = { this.setTileSize(mapSize); // The parent element is the map - let propertyArr = getPropertyList(map); - if (propertyArr) { - let aPropertyDict = {}; - for (i = 0; i < propertyArr.length; i++) { - aPropertyDict[propertyArr[i].getAttribute('name')] = propertyArr[i].getAttribute('value'); - } - this.properties = aPropertyDict; - } + this.properties = getPropertyList(map); } // PARSE @@ -692,15 +714,7 @@ cc.TMXMapInfo.prototype = { for (let tIdx = 0; tIdx < tiles.length; tIdx++) { let t = tiles[tIdx]; this.parentGID = parseInt(tileset.firstGid) + parseInt(t.getAttribute('id') || 0); - let tp = getPropertyList(t); - if (tp) { - let dict = {}; - for (j = 0; j < tp.length; j++) { - let name = tp[j].getAttribute('name'); - dict[name] = tp[j].getAttribute('value'); - } - this._tileProperties[this.parentGID] = dict; - } + this._tileProperties[this.parentGID] = getPropertyList(t); } } } @@ -839,15 +853,8 @@ cc.TMXMapInfo.prototype = { if (draworder) objectGroup._draworder = draworder; - let groupProps = getPropertyList(selGroup); - if (groupProps) { - let parsedProps = {}; - for (let j = 0; j < groupProps.length; j++) { - parsedProps[groupProps[j].getAttribute('name')] = groupProps[j].getAttribute('value'); - } - // set the properties to the group - objectGroup.setProperties(parsedProps); - } + // set the properties to the group + objectGroup.setProperties(getPropertyList(selGroup)); let objects = selGroup.getElementsByTagName('object'); if (objects) { @@ -872,11 +879,7 @@ cc.TMXMapInfo.prototype = { objectProp["rotation"] = parseFloat(selObj.getAttribute('rotation')) || 0; - let docObjProps = getPropertyList(selObj); - if (docObjProps) { - for (let k = 0; k < docObjProps.length; k++) - objectProp[docObjProps[k].getAttribute('name')] = docObjProps[k].getAttribute('value'); - } + getPropertyList(selObj, objectProp); // visible let visibleAttr = selObj.getAttribute('visible'); From 1d8f3bb5f94602db8714092b9fdd31fa9a51c9eb Mon Sep 17 00:00:00 2001 From: ColinCollins <35832931+ColinCollins@users.noreply.github.com> Date: Tue, 21 Aug 2018 19:29:48 +0800 Subject: [PATCH 30/53] remove cc.info (#3128) --- cocos2d/core/CCDebug.js | 26 +---------------------- cocos2d/deprecated.js | 8 +++++-- extensions/dragonbones/lib/dragonBones.js | 2 +- test/qunit/unit-es5/_init.js | 1 - 4 files changed, 8 insertions(+), 29 deletions(-) diff --git a/cocos2d/core/CCDebug.js b/cocos2d/core/CCDebug.js index 33f683c99e..a11c8e2e05 100644 --- a/cocos2d/core/CCDebug.js +++ b/cocos2d/core/CCDebug.js @@ -93,7 +93,7 @@ let resetDebugSetting = function (mode) { }; } if (mode === DebugMode.INFO_FOR_WEB_PAGE) { - cc.log = cc.info = function () { + cc.log = function () { logToWebPage(cc.js.formatStr.apply(null, arguments)); }; } @@ -177,7 +177,6 @@ let resetDebugSetting = function (mode) { } if (CC_EDITOR) { cc.log = Editor.log; - cc.info = Editor.info; } else if (mode === DebugMode.INFO) { /** @@ -206,29 +205,6 @@ let resetDebugSetting = function (mode) { return console.log.apply(console, arguments); }; } - /** - * !#en - * Outputs an informational message to the Cocos Creator Console (editor) or Web Console (runtime). - * - In Cocos Creator, info is blue. - * - In Firefox and Chrome, a small "i" icon is displayed next to these items in the Web Console's log. - * !#zh - * 输出一条信息消息到 Cocos Creator 编辑器的 Console 或运行时 Web 端的 Console 中。 - * - 在 Cocos Creator 中,Info 信息显示是蓝色的。
- * - 在 Firefox 和 Chrome 中,Info 信息有着小 “i” 图标。 - * @method info - * @param {any} msg - A JavaScript string containing zero or more substitution strings. - * @param {any} ...subst - JavaScript objects with which to replace substitution strings within msg. This gives you additional control over the format of the output. - */ - if (CC_JSB) { - cc.info = (scriptEngineType === "JavaScriptCore") ? function () { - (console.info || console.log).apply(console, arguments); - } : (console.info || console.log); - } - else { - cc.info = function () { - (console.info || console.log).apply(console, arguments); - }; - } } }; diff --git a/cocos2d/deprecated.js b/cocos2d/deprecated.js index e76733d29d..6d3b4536da 100644 --- a/cocos2d/deprecated.js +++ b/cocos2d/deprecated.js @@ -26,7 +26,7 @@ var js = cc.js; -if (CC_DEV) { +if (CC_DEBUG) { function deprecateEnum (obj, oldPath, newPath, hasTypePrefixBefore) { if (!CC_SUPPORT_JIT) { @@ -143,7 +143,11 @@ if (CC_DEV) { })(); } } - + // remove cc.info + js.get(cc, 'info', function () { + cc.warnID(1400, 'cc.info', 'cc.log'); + return cc.log; + }); // cc.spriteFrameCache js.get(cc, "spriteFrameCache", function () { cc.errorID(1404); diff --git a/extensions/dragonbones/lib/dragonBones.js b/extensions/dragonbones/lib/dragonBones.js index 767e4c535a..6552d86ce8 100644 --- a/extensions/dragonbones/lib/dragonBones.js +++ b/extensions/dragonbones/lib/dragonBones.js @@ -46,7 +46,7 @@ var dragonBones; this._objects = []; this._eventManager = null; this._eventManager = eventManager; - console.info("DragonBones: " + DragonBones.VERSION + "\nWebsite: http://dragonbones.com/\nSource and Demos: https://github.com/DragonBones/"); + console.log("DragonBones: " + DragonBones.VERSION + "\nWebsite: http://dragonbones.com/\nSource and Demos: https://github.com/DragonBones/"); } DragonBones.prototype.advanceTime = function (passedTime) { if (this._objects.length > 0) { diff --git a/test/qunit/unit-es5/_init.js b/test/qunit/unit-es5/_init.js index 3d7c1522f3..8e046b1ce6 100644 --- a/test/qunit/unit-es5/_init.js +++ b/test/qunit/unit-es5/_init.js @@ -156,7 +156,6 @@ cc.engine = new (cc.Class({ Editor.log = cc.log; Editor.warn = cc.warn; Editor.error = cc.error; -Editor.info = cc.info; Editor.Utils = Editor.Utils || {}; Editor.Utils.UuidCache = {}; From 40864171e160a0e25777aa1f5e72a0b980305a5e Mon Sep 17 00:00:00 2001 From: ColinCollins <35832931+ColinCollins@users.noreply.github.com> Date: Wed, 22 Aug 2018 14:45:14 +0800 Subject: [PATCH 31/53] remove cc.info (#3131) --- CCDebugger.js | 26 +------------------------- cocos2d/deprecated.js | 8 ++++++-- test/qunit/unit-es5/_init.js | 1 - 3 files changed, 7 insertions(+), 28 deletions(-) diff --git a/CCDebugger.js b/CCDebugger.js index b4bc5ceaf6..2b90045f1f 100644 --- a/CCDebugger.js +++ b/CCDebugger.js @@ -163,7 +163,7 @@ cc._initDebugSetting = function (mode) { }; } if (mode === cc.DebugMode.INFO_FOR_WEB_PAGE) { - cc.log = cc.info = function () { + cc.log = function () { logToWebPage(cc.js.formatStr.apply(null, arguments)); }; } @@ -247,7 +247,6 @@ cc._initDebugSetting = function (mode) { } if (CC_EDITOR) { cc.log = Editor.log; - cc.info = Editor.info; } else if (mode === cc.DebugMode.INFO) { /** @@ -276,29 +275,6 @@ cc._initDebugSetting = function (mode) { return console.log.apply(console, arguments); }; } - /** - * !#en - * Outputs an informational message to the Cocos Creator Console (editor) or Web Console (runtime). - * - In Cocos Creator, info is blue. - * - In Firefox and Chrome, a small "i" icon is displayed next to these items in the Web Console's log. - * !#zh - * 输出一条信息消息到 Cocos Creator 编辑器的 Console 或运行时 Web 端的 Console 中。 - * - 在 Cocos Creator 中,Info 信息显示是蓝色的。
- * - 在 Firefox 和 Chrome 中,Info 信息有着小 “i” 图标。 - * @method info - * @param {any} msg - A JavaScript string containing zero or more substitution strings. - * @param {any} ...subst - JavaScript objects with which to replace substitution strings within msg. This gives you additional control over the format of the output. - */ - if (CC_JSB) { - cc.info = (scriptEngineType === "JavaScriptCore") ? function () { - (console.info || console.log).apply(console, arguments); - } : (console.info || console.log); - } - else { - cc.info = function () { - (console.info || console.log).apply(console, arguments); - }; - } } }; diff --git a/cocos2d/deprecated.js b/cocos2d/deprecated.js index 81a3b92ebd..d5932d68d0 100644 --- a/cocos2d/deprecated.js +++ b/cocos2d/deprecated.js @@ -26,7 +26,7 @@ var js = cc.js; -if (CC_DEV) { +if (CC_DEBUG) { // cc.spriteFrameCache js.get(cc, "spriteFrameCache", function () { @@ -229,7 +229,11 @@ if (CC_DEV) { cc.errorID(1400, 'cc.PI', 'Math.PI'); return Math.PI; }); - + // remove cc.info + js.get(cc, 'info', function () { + cc.warnID(1400, 'cc.info', 'cc.log'); + return cc.log; + }); if (cc.TiledLayer) { /** * Get the Tile set information for the layer. diff --git a/test/qunit/unit-es5/_init.js b/test/qunit/unit-es5/_init.js index 847b1dd7da..232b301312 100644 --- a/test/qunit/unit-es5/_init.js +++ b/test/qunit/unit-es5/_init.js @@ -156,7 +156,6 @@ cc.engine = new (cc.Class({ Editor.log = cc.log; Editor.warn = cc.warn; Editor.error = cc.error; -Editor.info = cc.info; Editor.Utils = Editor.Utils || {}; Editor.Utils.UuidCache = {}; From f5b81db4c25bece14ab74b428b9de2cae3d1bbef Mon Sep 17 00:00:00 2001 From: PP Date: Wed, 22 Aug 2018 14:47:29 +0800 Subject: [PATCH 32/53] hide editbox input onDisable when stayOnTop (#3129) --- cocos2d/core/components/editbox/CCEditBox.js | 8 ++++++++ .../core/components/editbox/CCEditBoxImpl.js | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/cocos2d/core/components/editbox/CCEditBox.js b/cocos2d/core/components/editbox/CCEditBox.js index 61a2e93cc1..a5aad021e9 100644 --- a/cocos2d/core/components/editbox/CCEditBox.js +++ b/cocos2d/core/components/editbox/CCEditBox.js @@ -577,6 +577,14 @@ let EditBox = cc.Class({ this._impl.clear(); }, + onEnable () { + this._impl && this._impl.onEnable(); + }, + + onDisable () { + this._impl && this._impl.onDisable(); + }, + __preload () { if (!CC_EDITOR) { this._registerEvent(); diff --git a/cocos2d/core/components/editbox/CCEditBoxImpl.js b/cocos2d/core/components/editbox/CCEditBoxImpl.js index 3262874a0e..c0f328cc32 100644 --- a/cocos2d/core/components/editbox/CCEditBoxImpl.js +++ b/cocos2d/core/components/editbox/CCEditBoxImpl.js @@ -93,6 +93,25 @@ let EditBoxImpl = cc.Class({ this.__orientationChanged = null; }, + onEnable () { + if (!this._edTxt) { + return; + } + if (this._alwaysOnTop) { + this._edTxt.style.display = ''; + } + else { + this._edTxt.style.display = 'none'; + } + }, + + onDisable () { + if (!this._edTxt) { + return; + } + this._edTxt.style.display = 'none'; + }, + setTabIndex (index) { if (this._edTxt) { this._edTxt.tabIndex = index; From 9877760e9859861b1ed6d9fcb69d18d06d6508ef Mon Sep 17 00:00:00 2001 From: Knox Date: Wed, 22 Aug 2018 14:49:17 +0800 Subject: [PATCH 33/53] fix tiledtile opacity and no display bug (#3124) * fix tiledTile opacity invalid and rm layer * change start to __preload in tilemap * fix _positionForHexAt bug --- cocos2d/tilemap/CCTiledLayer.js | 36 ++++++++--------- cocos2d/tilemap/CCTiledMap.js | 2 +- cocos2d/tilemap/CCTiledTile.js | 54 +++++++------------------- cocos2d/tilemap/tmx-layer-assembler.js | 4 +- 4 files changed, 36 insertions(+), 60 deletions(-) diff --git a/cocos2d/tilemap/CCTiledLayer.js b/cocos2d/tilemap/CCTiledLayer.js index 78a49ae27a..5c830b20ae 100644 --- a/cocos2d/tilemap/CCTiledLayer.js +++ b/cocos2d/tilemap/CCTiledLayer.js @@ -154,36 +154,36 @@ let TiledLayer = cc.Class({ ); }, - _positionForHexAt (x, y) { - let xy; + _positionForHexAt (row, col) { + let tileWidth = this._mapTileSize.width; + let tileHeight = this._mapTileSize.height; + let cols = this._layerSize.height; let offset = this._tileset.tileOffset; - + let centerWidth = this.node.width / 2; + let centerHeight = this.node.height / 2; let odd_even = (this._staggerIndex === cc.TiledMap.StaggerIndex.STAGGERINDEX_ODD) ? 1 : -1; + let x = 0, y = 0; switch (this._staggerAxis) { case cc.TiledMap.StaggerAxis.STAGGERAXIS_Y: let diffX = 0; - if (y % 2 === 1) - { - diffX = this._mapTileSize.width/2 * odd_even; + let diffX1 = (this._staggerIndex === cc.TiledMap.StaggerIndex.STAGGERINDEX_ODD) ? 0 : tileWidth / 2; + if (col % 2 === 1) { + diffX = tileWidth / 2 * odd_even; } - xy = cc.v2(x * this._mapTileSize.width+diffX+offset.x, - (this._layerSize.height - y - 1) * (this._mapTileSize.height-(this._mapTileSize.height-this._hexSideLength)/2)-offset.y); + x = row * tileWidth + diffX + diffX1 + offset.x - centerWidth; + y = (cols - col - 1) * (tileHeight - (tileHeight - this._hexSideLength) / 2) - offset.y - centerHeight; break; case cc.TiledMap.StaggerAxis.STAGGERAXIS_X: let diffY = 0; - if (x % 2 === 1) - { - diffY = this._mapTileSize.height/2 * -odd_even; + let diffY1 = (this._staggerIndex === cc.TiledMap.StaggerIndex.STAGGERINDEX_ODD) ? tileHeight / 2 : 0; + if (row % 2 === 1) { + diffY = tileHeight / 2 * -odd_even; } - - xy = cc.v2(x * (this._mapTileSize.width-(this._mapTileSize.width-this._hexSideLength)/2)+offset.x, - (this._layerSize.height - y - 1) * this._mapTileSize.height + diffY-offset.y); - break; - default: - xy = cc.v2(0, 0); + x = row * (tileWidth - (tileWidth - this._hexSideLength) / 2) + offset.x - centerWidth; + y = (cols - col - 1) * tileHeight + diffY + diffY1 - offset.y - centerHeight; break; } - return xy; + return cc.v2(x, y); }, /** diff --git a/cocos2d/tilemap/CCTiledMap.js b/cocos2d/tilemap/CCTiledMap.js index 8e59848c65..601d1e8598 100644 --- a/cocos2d/tilemap/CCTiledMap.js +++ b/cocos2d/tilemap/CCTiledMap.js @@ -423,7 +423,7 @@ let TiledMap = cc.Class({ return this._tileProperties[GID]; }, - start () { + __preload () { if (this._tmxFile) { // refresh layer entities this._applyFile(); diff --git a/cocos2d/tilemap/CCTiledTile.js b/cocos2d/tilemap/CCTiledTile.js index 787160bf51..60527dc5ef 100644 --- a/cocos2d/tilemap/CCTiledTile.js +++ b/cocos2d/tilemap/CCTiledTile.js @@ -42,12 +42,14 @@ let TiledTile = cc.Class({ menu: 'i18n:MAIN_MENU.component.renderers/TiledTile', }, + ctor () { + this._layer = null; + }, + properties: { _x: 0, _y: 0, - _gid: 0, - - _layer: null, + _gid: -1, /** * !#en Specify the TiledTile horizontal coordinate,use map tile as the unit. @@ -109,46 +111,14 @@ let TiledTile = cc.Class({ this._gid = value; }, type: cc.Integer - }, - - /** - * !#en Specify which TiledLayer the TiledTile belong to. - * !#zh 指定 TiledTile 属于哪一个 TiledLayer - * @property {TiledLayer} layer - */ - layer: { - type: cc.TiledLayer, - get () { - return this._layer; - }, - set (value) { - if (value === this._layer) return; - this._resetTile(); - this._layer = value; - this._updateInfo(); - } } }, onEnable () { - if (CC_EDITOR) { - let parent = this.node.parent; - if (!this._layer && !(parent instanceof cc.Scene)) { - this._layer = parent.getComponent(cc.TiledLayer); - this._updateInfo(); - } - } - else if (this._layer) { - let tile = this._layer.getTiledTileAt(this._x, this._y); - if (tile) { - if (tile !== this) { - cc.warn('There is already a TiledTile at [%s, %s]', this._x, this._x); - } - } - else { - this._layer.setTiledTileAt(this._x, this._y, this); - } - } + let parent = this.node.parent; + this._layer = parent.getComponent(cc.TiledLayer); + this._resetTile(); + this._updateInfo(); }, onDisable () { @@ -171,7 +141,11 @@ let TiledTile = cc.Class({ } this.node.setPosition(this._layer.getPositionAt(x, y)); - this._gid = this._layer.getTileGIDAt(x, y); + + if (this._gid === -1) { + this._gid = this._layer.getTileGIDAt(x, y); + } + this._layer.setTiledTileAt(x, y, this); }, }); diff --git a/cocos2d/tilemap/tmx-layer-assembler.js b/cocos2d/tilemap/tmx-layer-assembler.js index 0aca18ed85..dde3eb961a 100644 --- a/cocos2d/tilemap/tmx-layer-assembler.js +++ b/cocos2d/tilemap/tmx-layer-assembler.js @@ -104,6 +104,7 @@ let tmxAssembler = { let renderData = comp._renderData; let data = renderData._data; let color = node._color._val; + let opacity = node._color.a; renderData.dataLength = renderData.vertexCount = renderData.indiceCount = 0; @@ -254,7 +255,8 @@ let tmxAssembler = { // color color2 = color; - color = tiledNode.color._val; + let newOpacity = (tiledNode.opacity * opacity) / 255; + color = tiledNode.color.setA(newOpacity)._val; // transform a2 = a; b2 = b; c2 = c; d2 = d; tx2 = tx; ty2 = ty; From 2791fda5171310b5720b5300f6757f6bd9d6714d Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 23 Aug 2018 10:40:59 +0800 Subject: [PATCH 34/53] Fix cc.view._resizeWithBrowserSize typo (#3130) --- cocos2d/core/platform/CCView.js | 4 ++-- cocos2d/core/utils/misc.js | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/cocos2d/core/platform/CCView.js b/cocos2d/core/platform/CCView.js index 8026334481..7b5f49aeb7 100644 --- a/cocos2d/core/platform/CCView.js +++ b/cocos2d/core/platform/CCView.js @@ -274,8 +274,8 @@ cc.js.mixin(View.prototype, { } } else { //disable - if (this.__resizeWithBrowserSize) { - this.__resizeWithBrowserSize = false; + if (this._resizeWithBrowserSize) { + this._resizeWithBrowserSize = false; window.removeEventListener('resize', this._resizeEvent); window.removeEventListener('orientationchange', this._orientationChange); } diff --git a/cocos2d/core/utils/misc.js b/cocos2d/core/utils/misc.js index d08f894280..ea5e4fef24 100644 --- a/cocos2d/core/utils/misc.js +++ b/cocos2d/core/utils/misc.js @@ -25,7 +25,6 @@ ****************************************************************************/ var js = require('../platform/js'); -var sys = require('../platform/CCSys'); /** * misc utilities From 1c814eca5be29d888ce711b564bcb0d960c21c02 Mon Sep 17 00:00:00 2001 From: Knox Date: Thu, 23 Aug 2018 11:14:47 +0800 Subject: [PATCH 35/53] fix video-player fullscreen invalid in ios for fireball/issues/8239 (#3134) * fix video-player fullscreen invalid in ios for fireball/issues/8239 * refine code --- cocos2d/videoplayer/video-player-impl.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/cocos2d/videoplayer/video-player-impl.js b/cocos2d/videoplayer/video-player-impl.js index 82db656943..5b55b5ae22 100644 --- a/cocos2d/videoplayer/video-player-impl.js +++ b/cocos2d/videoplayer/video-player-impl.js @@ -347,10 +347,22 @@ let VideoPlayerImpl = cc.Class({ let video = this._video; if (!video) return; - if (enable) - cc.screen.requestFullScreen(video); - else - cc.screen.exitFullScreen(video); + if (sys.os === sys.OS_IOS && sys.isBrowser) { + if (enable) { + video.webkitEnterFullscreen && video.webkitEnterFullscreen(); + } + else { + video.webkitExitFullscreen && video.webkitExitFullscreen(); + } + } + else { + if (enable) { + cc.screen.requestFullScreen(video); + } + else { + cc.screen.exitFullScreen(video); + } + } }, From 30651481fbdbd3db88507c9057f65268c6052213 Mon Sep 17 00:00:00 2001 From: Knox Date: Thu, 23 Aug 2018 15:23:03 +0800 Subject: [PATCH 36/53] fix global variable i (#3135) --- cocos2d/tilemap/CCTMXXMLParser.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cocos2d/tilemap/CCTMXXMLParser.js b/cocos2d/tilemap/CCTMXXMLParser.js index 4b497a3fbb..67afeb90e1 100644 --- a/cocos2d/tilemap/CCTMXXMLParser.js +++ b/cocos2d/tilemap/CCTMXXMLParser.js @@ -25,6 +25,8 @@ THE SOFTWARE. ****************************************************************************/ +'use strict'; + const codec = require('../compression/ZipUtils'); const zlib = require('../compression/zlib.min'); const js = require('../core/platform/js'); @@ -200,7 +202,7 @@ function getPropertyList (node, map) { } map = map || {}; - for (i = 0; i < res.length; i++) { + for (let i = 0; i < res.length; i++) { let element = res[i]; let name = element.getAttribute('name'); let type = element.getAttribute('type') || 'string'; From f0f26a821d99d9987e5d60bfaba01fe800270e69 Mon Sep 17 00:00:00 2001 From: Knox Date: Thu, 23 Aug 2018 15:48:51 +0800 Subject: [PATCH 37/53] sync gid for fireball/issues/8048 (#3137) sync gid between TiledLayer and TiledTile --- cocos2d/tilemap/CCTiledTile.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/cocos2d/tilemap/CCTiledTile.js b/cocos2d/tilemap/CCTiledTile.js index 60527dc5ef..344951aa5e 100644 --- a/cocos2d/tilemap/CCTiledTile.js +++ b/cocos2d/tilemap/CCTiledTile.js @@ -49,7 +49,6 @@ let TiledTile = cc.Class({ properties: { _x: 0, _y: 0, - _gid: -1, /** * !#en Specify the TiledTile horizontal coordinate,use map tile as the unit. @@ -105,10 +104,15 @@ let TiledTile = cc.Class({ */ gid: { get () { - return this._gid; + if (this._layer) { + return this._layer.getTileGIDAt(this._x, this._y); + } + return 0; }, set (value) { - this._gid = value; + if (this._layer) { + this._layer.setTileGIDAt(value, this._x, this._y); + } }, type: cc.Integer } @@ -133,19 +137,13 @@ let TiledTile = cc.Class({ _updateInfo () { if (!this._layer) return; - + let x = this._x, y = this._y; if (this._layer.getTiledTileAt(x, y)) { cc.warn('There is already a TiledTile at [%s, %s]', x, y); return; } - this.node.setPosition(this._layer.getPositionAt(x, y)); - - if (this._gid === -1) { - this._gid = this._layer.getTileGIDAt(x, y); - } - this._layer.setTiledTileAt(x, y, this); }, }); From 79542d65dc19c8718cb54c9afa022e8f91855f48 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Thu, 23 Aug 2018 17:33:29 +0800 Subject: [PATCH 38/53] fix alignOnce widget not restore after editing animation (#3139) --- cocos2d/core/base-ui/CCWidgetManager.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cocos2d/core/base-ui/CCWidgetManager.js b/cocos2d/core/base-ui/CCWidgetManager.js index 63a3b303c2..51f67021f5 100644 --- a/cocos2d/core/base-ui/CCWidgetManager.js +++ b/cocos2d/core/base-ui/CCWidgetManager.js @@ -270,8 +270,9 @@ function refreshScene () { // check animation editor if (CC_EDITOR && !Editor.isBuilder) { var AnimUtils = Editor.require('scene://utils/animation'); - if (AnimUtils) { - var nowPreviewing = !!AnimUtils.Cache.animation; + var EditMode = Editor.require('scene://edit-mode'); + if (AnimUtils && EditMode) { + var nowPreviewing = (EditMode.curMode().name === 'animation' && !!AnimUtils.Cache.animation); if (nowPreviewing !== animationState.previewing) { animationState.previewing = nowPreviewing; if (nowPreviewing) { From 410f9cf77babcf4e3ba0af4293a13ee8a665086a Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 23 Aug 2018 18:16:09 +0800 Subject: [PATCH 39/53] remove jsb downloaders from engine (#3138) --- .../core/load-pipeline/binary-downloader.js | 18 +---- cocos2d/core/load-pipeline/text-downloader.js | 65 +++++++------------ 2 files changed, 26 insertions(+), 57 deletions(-) diff --git a/cocos2d/core/load-pipeline/binary-downloader.js b/cocos2d/core/load-pipeline/binary-downloader.js index 131948cf63..de4097f4ea 100644 --- a/cocos2d/core/load-pipeline/binary-downloader.js +++ b/cocos2d/core/load-pipeline/binary-downloader.js @@ -24,23 +24,8 @@ THE SOFTWARE. ****************************************************************************/ -if (CC_JSB) { - module.exports = function (item, callback) { - var url = item.url; - - var result = jsb.fileUtils.getDataFromFile(url); - if (result) { - return result; - } - else { - return new Error('Download binary file failed: ' + url); - } - }; -} -else { function downloadBinary (item, callback) { var url = item.url; - var self = this; var xhr = cc.loader.getXMLHttpRequest(), errInfo = 'Load binary data failed: ' + url + ''; xhr.open('GET', url, true); @@ -64,5 +49,4 @@ function downloadBinary (item, callback) { xhr.send(null); } -module.exports = downloadBinary; -} \ No newline at end of file +module.exports = downloadBinary; \ No newline at end of file diff --git a/cocos2d/core/load-pipeline/text-downloader.js b/cocos2d/core/load-pipeline/text-downloader.js index deb9970f35..a64ca7f740 100644 --- a/cocos2d/core/load-pipeline/text-downloader.js +++ b/cocos2d/core/load-pipeline/text-downloader.js @@ -23,49 +23,34 @@ THE SOFTWARE. ****************************************************************************/ -if (CC_JSB) { - module.exports = function (item) { - var url = item.url; +var urlAppendTimestamp = require('./utils').urlAppendTimestamp; - var result = jsb.fileUtils.getStringFromFile(url); - if (typeof result === 'string' && result) { - return result; - } - else { - return new Error('Download text failed: ' + url); - } - }; -} -else { - var urlAppendTimestamp = require('./utils').urlAppendTimestamp; +module.exports = function (item, callback) { + var url = item.url; + url = urlAppendTimestamp(url); - module.exports = function (item, callback) { - var url = item.url; - url = urlAppendTimestamp(url); - - var xhr = cc.loader.getXMLHttpRequest(), - errInfo = 'Load text file failed: ' + url; - xhr.open('GET', url, true); - if (xhr.overrideMimeType) xhr.overrideMimeType('text\/plain; charset=utf-8'); - xhr.onload = function () { - if (xhr.readyState === 4) { - if (xhr.status === 200 || xhr.status === 0) { - callback(null, xhr.responseText); - } - else { - callback({status:xhr.status, errorMessage:errInfo + '(wrong status)'}); - } + var xhr = cc.loader.getXMLHttpRequest(), + errInfo = 'Load text file failed: ' + url; + xhr.open('GET', url, true); + if (xhr.overrideMimeType) xhr.overrideMimeType('text\/plain; charset=utf-8'); + xhr.onload = function () { + if (xhr.readyState === 4) { + if (xhr.status === 200 || xhr.status === 0) { + callback(null, xhr.responseText); } else { - callback({status:xhr.status, errorMessage:errInfo + '(wrong readyState)'}); + callback({status:xhr.status, errorMessage:errInfo + '(wrong status)'}); } - }; - xhr.onerror = function(){ - callback({status:xhr.status, errorMessage:errInfo + '(error)'}); - }; - xhr.ontimeout = function(){ - callback({status:xhr.status, errorMessage:errInfo + '(time out)'}); - }; - xhr.send(null); + } + else { + callback({status:xhr.status, errorMessage:errInfo + '(wrong readyState)'}); + } }; -} + xhr.onerror = function(){ + callback({status:xhr.status, errorMessage:errInfo + '(error)'}); + }; + xhr.ontimeout = function(){ + callback({status:xhr.status, errorMessage:errInfo + '(time out)'}); + }; + xhr.send(null); +}; \ No newline at end of file From 94bd9a7bd3c0294681d9452b6ef323d7dc75ce9f Mon Sep 17 00:00:00 2001 From: yongminghuang <339698778@qq.com> Date: Fri, 24 Aug 2018 11:03:22 +0800 Subject: [PATCH 40/53] Fix load null resources issue in cc.loader (#3141) --- cocos2d/core/load-pipeline/CCLoader.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cocos2d/core/load-pipeline/CCLoader.js b/cocos2d/core/load-pipeline/CCLoader.js index d51197fd7c..6849ec8e69 100644 --- a/cocos2d/core/load-pipeline/CCLoader.js +++ b/cocos2d/core/load-pipeline/CCLoader.js @@ -230,8 +230,12 @@ proto.load = function(resources, progressCallback, completeCallback) { var singleRes = false; var res; if (!(resources instanceof Array)) { - singleRes = true; - resources = resources ? [resources] : []; + if (resources) { + singleRes = true; + resources = [resources]; + } else { + resources = []; + } } _sharedResources.length = 0; From 4f734a806d1fd7c4073fb064fddc961384fe67af Mon Sep 17 00:00:00 2001 From: ColinCollins <35832931+ColinCollins@users.noreply.github.com> Date: Fri, 24 Aug 2018 13:41:14 +0800 Subject: [PATCH 41/53] modify the note for periodic function (#3140) --- cocos2d/core/components/CCComponent.js | 42 +++++++++++++++++--------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/cocos2d/core/components/CCComponent.js b/cocos2d/core/components/CCComponent.js index bbe0c3b528..9775a43a2e 100644 --- a/cocos2d/core/components/CCComponent.js +++ b/cocos2d/core/components/CCComponent.js @@ -217,8 +217,10 @@ var Component = cc.Class({ // We provide Pre methods, which are called right before something happens, and Post methods which are called right after something happens. /** - * !#en Update is called every frame, if the Component is enabled. - * !#zh 如果该组件启用,则每帧调用 update。 + * !#en Update is called every frame, if the Component is enabled.
+ * This is a lifecycle method. It may not be implemented in the super class. You can only call its super class method inside it. It should not be called manually elsewhere. + * !#zh 如果该组件启用,则每帧调用 update。
+ * 该方法为生命周期方法,父类未必会有实现。并且你只能在该方法内部调用父类的实现,不可在其它地方直接调用该方法。 * @method update * @param {Number} dt - the delta time in seconds it took to complete the last frame * @protected @@ -226,8 +228,10 @@ var Component = cc.Class({ update: null, /** - * !#en LateUpdate is called every frame, if the Component is enabled. - * !#zh 如果该组件启用,则每帧调用 LateUpdate。 + * !#en LateUpdate is called every frame, if the Component is enabled.
+ * This is a lifecycle method. It may not be implemented in the super class. You can only call its super class method inside it. It should not be called manually elsewhere. + * !#zh 如果该组件启用,则每帧调用 LateUpdate。
+ * 该方法为生命周期方法,父类未必会有实现。并且你只能在该方法内部调用父类的实现,不可在其它地方直接调用该方法。 * @method lateUpdate * @protected */ @@ -247,9 +251,11 @@ var Component = cc.Class({ /** * !#en * When attaching to an active node or its node first activated. - * onLoad is always called before any start functions, this allows you to order initialization of scripts. + * onLoad is always called before any start functions, this allows you to order initialization of scripts.
+ * This is a lifecycle method. It may not be implemented in the super class. You can only call its super class method inside it. It should not be called manually elsewhere. * !#zh - * 当附加到一个激活的节点上或者其节点第一次激活时候调用。onLoad 总是会在任何 start 方法调用前执行,这能用于安排脚本的初始化顺序。 + * 当附加到一个激活的节点上或者其节点第一次激活时候调用。onLoad 总是会在任何 start 方法调用前执行,这能用于安排脚本的初始化顺序。
+ * 该方法为生命周期方法,父类未必会有实现。并且你只能在该方法内部调用父类的实现,不可在其它地方直接调用该方法。 * @method onLoad * @protected */ @@ -258,33 +264,41 @@ var Component = cc.Class({ /** * !#en * Called before all scripts' update if the Component is enabled the first time. - * Usually used to initialize some logic which need to be called after all components' `onload` methods called. + * Usually used to initialize some logic which need to be called after all components' `onload` methods called.
+ * This is a lifecycle method. It may not be implemented in the super class. You can only call its super class method inside it. It should not be called manually elsewhere. * !#zh - * 如果该组件第一次启用,则在所有组件的 update 之前调用。通常用于需要在所有组件的 onLoad 初始化完毕后执行的逻辑。 + * 如果该组件第一次启用,则在所有组件的 update 之前调用。通常用于需要在所有组件的 onLoad 初始化完毕后执行的逻辑。
+ * 该方法为生命周期方法,父类未必会有实现。并且你只能在该方法内部调用父类的实现,不可在其它地方直接调用该方法。 * @method start * @protected */ start: null, /** - * !#en Called when this component becomes enabled and its node is active. - * !#zh 当该组件被启用,并且它的节点也激活时。 + * !#en Called when this component becomes enabled and its node is active.
+ * This is a lifecycle method. It may not be implemented in the super class. You can only call its super class method inside it. It should not be called manually elsewhere. + * !#zh 当该组件被启用,并且它的节点也激活时。
+ * 该方法为生命周期方法,父类未必会有实现。并且你只能在该方法内部调用父类的实现,不可在其它地方直接调用该方法。 * @method onEnable * @protected */ onEnable: null, /** - * !#en Called when this component becomes disabled or its node becomes inactive. - * !#zh 当该组件被禁用或节点变为无效时调用。 + * !#en Called when this component becomes disabled or its node becomes inactive.
+ * This is a lifecycle method. It may not be implemented in the super class. You can only call its super class method inside it. It should not be called manually elsewhere. + * !#zh 当该组件被禁用或节点变为无效时调用。
+ * 该方法为生命周期方法,父类未必会有实现。并且你只能在该方法内部调用父类的实现,不可在其它地方直接调用该方法。 * @method onDisable * @protected */ onDisable: null, /** - * !#en Called when this component will be destroyed. - * !#zh 当该组件被销毁时调用 + * !#en Called when this component will be destroyed.
+ * This is a lifecycle method. It may not be implemented in the super class. You can only call its super class method inside it. It should not be called manually elsewhere. + * !#zh 当该组件被销毁时调用
+ * 该方法为生命周期方法,父类未必会有实现。并且你只能在该方法内部调用父类的实现,不可在其它地方直接调用该方法。 * @method onDestroy * @protected */ From 2ddba1da00ea17edc5302c7a1de9c6b30120c661 Mon Sep 17 00:00:00 2001 From: wdzhangchukong <38641173+wdzhangchukong@users.noreply.github.com> Date: Mon, 27 Aug 2018 15:54:09 +0800 Subject: [PATCH 42/53] Remove some name about Cocos (#3145) * Rename __ccgl and __cccanvas * Remove __jsc__ * Make CC_RUNTIME be true in runtime * Judge loadRuntime with function --- cocos2d/core/CCGame.js | 2 +- cocos2d/core/platform/CCSys.js | 4 ++-- cocos2d/core/renderer/render-engine.jsb.js | 6 +++--- predefine.js | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cocos2d/core/CCGame.js b/cocos2d/core/CCGame.js index 545c1eb462..7ae97eb906 100644 --- a/cocos2d/core/CCGame.js +++ b/cocos2d/core/CCGame.js @@ -666,7 +666,7 @@ var game = { localCanvas = window.sharedCanvas || wx.getSharedCanvas(); } else if (CC_JSB) { - localCanvas = window.__cccanvas; + localCanvas = window.__canvas; } else { localCanvas = canvas; diff --git a/cocos2d/core/platform/CCSys.js b/cocos2d/core/platform/CCSys.js index f020482aca..01a129a2df 100644 --- a/cocos2d/core/platform/CCSys.js +++ b/cocos2d/core/platform/CCSys.js @@ -1130,7 +1130,7 @@ function initSys () { sys.garbageCollect = function () { // N/A in web if (CC_JSB) { - __jsc__.garbageCollect(); + jsb.garbageCollect(); } }; @@ -1141,7 +1141,7 @@ function initSys () { sys.dumpRoot = function () { // N/A in web if (CC_JSB) { - __jsc__.dumpRoot(); + jsb.dumpRoot(); } }; diff --git a/cocos2d/core/renderer/render-engine.jsb.js b/cocos2d/core/renderer/render-engine.jsb.js index 4f6952f508..5fc7a5a197 100644 --- a/cocos2d/core/renderer/render-engine.jsb.js +++ b/cocos2d/core/renderer/render-engine.jsb.js @@ -30,7 +30,7 @@ // Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. -var gl = window.__ccgl; +var gl = window.__gl; var _filterGL = [ [ gl.GL_NEAREST, gl.GL_NEAREST_MIPMAP_NEAREST, gl.GL_NEAREST_MIPMAP_LINEAR ], @@ -369,11 +369,11 @@ VertexFormat.prototype.element = function element (attrName) { // Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. -var gl$1 = window.__ccgl; +var gl$1 = window.__gl; var gfx$1 = window.gfx; window.device = gfx$1.Device.getInstance(); -window.device._gl = window.__ccgl; +window.device._gl = window.__gl; //FIXME: window.device._stats = { vb: 0 }; diff --git a/predefine.js b/predefine.js index 9f2e4ef449..58b0043fad 100644 --- a/predefine.js +++ b/predefine.js @@ -137,7 +137,7 @@ defineMacro('CC_JSB', defined('jsb')); defineMacro('CC_BUILD', false); defineMacro('CC_WECHATGAME', defined('wx') && wx.getSystemInfoSync); defineMacro('CC_QQPLAY', defined('bk')); -defineMacro('CC_RUNTIME', false); +defineMacro('CC_RUNTIME', 'function' === typeof loadRuntime); defineMacro('CC_SUPPORT_JIT', !(CC_WECHATGAME || CC_QQPLAY || CC_RUNTIME)); // From b7df07d1f8307dd8c958dd498143e84ed9444388 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Mon, 27 Aug 2018 19:44:41 +0800 Subject: [PATCH 43/53] Fix particle simulator step logic (#3150) * Fix particle simulator step for short emission * Improve particle simulator step --- cocos2d/particle/particle-simulator.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/cocos2d/particle/particle-simulator.js b/cocos2d/particle/particle-simulator.js index d27816e04d..91943093cd 100644 --- a/cocos2d/particle/particle-simulator.js +++ b/cocos2d/particle/particle-simulator.js @@ -293,8 +293,9 @@ Simulator.prototype.step = function (dt) { } this.elapsed += dt; - if (psys.duration !== -1 && psys.duration < this.elapsed) + if (psys.duration !== -1 && psys.duration < this.elapsed) { psys.stopSystem(); + } } // Request buffer for particles @@ -315,10 +316,11 @@ Simulator.prototype.step = function (dt) { _tpa.x = _tpa.y = _tpb.x = _tpb.y = _tpc.x = _tpc.y = 0; let particle = particles[particleIdx]; - // life - particle.timeToLive -= dt; if (particle.timeToLive > 0) { + // life + particle.timeToLive -= dt; + // Mode A: gravity, direction, tangential accel & radial accel if (psys.emitterMode === cc.ParticleSystem.EmitterMode.GRAVITY) { let tmp = _tpc, radial = _tpa, tangential = _tpb; @@ -401,11 +403,6 @@ Simulator.prototype.step = function (dt) { } pool.put(deadParticle); particles.length--; - - if (particles.length === 0) { - this.finished = true; - psys._finishedSimulation(); - } } } @@ -413,6 +410,10 @@ Simulator.prototype.step = function (dt) { buffer.uploadData(); psys._ia._count = particles.length * 6; } + else if (!this.active) { + this.finished = true; + psys._finishedSimulation(); + } } module.exports = Simulator; \ No newline at end of file From 2f807b6ca8fab1cf1453ef1cac558c20ea0aac08 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Tue, 28 Aug 2018 00:42:32 +0800 Subject: [PATCH 44/53] Update stencil manager impl to avoid rendering artifact on mi5 (#3133) * Update stencil manager impl to avoid rendering artifact on mi5 * Cleanup maskEndAssembler * Fix post update render data in mask * Fix image stencil issue * Merge frontMaterial & endMaterial --- cocos2d/core/components/CCMask.js | 58 ++++++----------- .../webgl/assemblers/mask-assembler.js | 65 ++++++++++--------- .../core/renderer/webgl/stencil-manager.js | 51 ++++++++++----- 3 files changed, 87 insertions(+), 87 deletions(-) diff --git a/cocos2d/core/components/CCMask.js b/cocos2d/core/components/CCMask.js index f401cd5a5c..35f58a94f5 100644 --- a/cocos2d/core/components/CCMask.js +++ b/cocos2d/core/components/CCMask.js @@ -176,11 +176,9 @@ let Mask = cc.Class({ cc.warnID(4201); return; } - if (this._frontMaterial) { - this._frontMaterial.alphaThreshold = this.alphaThreshold; - this._endMaterial.alphaThreshold = this.alphaThreshold; - this._frontMaterial.updateHash(); - this._endMaterial._hash = -this._frontMaterial._hash; + if (this._material) { + this._material.alphaThreshold = this.alphaThreshold; + this._material.updateHash(); } } }, @@ -277,7 +275,7 @@ let Mask = cc.Class({ this.node.on(cc.Node.EventType.SIZE_CHANGED, this._updateGraphics, this); this.node.on(cc.Node.EventType.ANCHOR_CHANGED, this._updateGraphics, this); - this.node._renderFlag |= RenderFlow.FLAG_POST_RENDER | RenderFlow.FLAG_POST_UPDATE_RENDER_DATA; + this.node._renderFlag |= RenderFlow.FLAG_POST_RENDER; this._activateMaterial(); }, @@ -290,14 +288,12 @@ let Mask = cc.Class({ this.node.off(cc.Node.EventType.SIZE_CHANGED, this._updateGraphics, this); this.node.off(cc.Node.EventType.ANCHOR_CHANGED, this._updateGraphics, this); - this.node._renderFlag &= ~(RenderFlow.FLAG_POST_RENDER | RenderFlow.FLAG_POST_UPDATE_RENDER_DATA); + this.node._renderFlag &= ~RenderFlow.FLAG_POST_RENDER; }, onDestroy () { this._super(); this._graphics.destroy(); - this._frontMaterial = null; - this._endMaterial = null; }, _resizeNodeToTargetNode: CC_EDITOR && function () { @@ -346,40 +342,24 @@ let Mask = cc.Class({ // WebGL if (cc.game.renderType !== cc.game.RENDER_TYPE_CANVAS) { // Init material - if (!this._frontMaterial) { - this._frontMaterial = new StencilMaterial(); - this._endMaterial = new StencilMaterial(); + if (!this._material) { + this._material = new StencilMaterial(); } // Reset material if (this._type === MaskType.IMAGE_STENCIL) { let texture = this.spriteFrame.getTexture(); - this._frontMaterial.useModel = false; - this._frontMaterial.useTexture = true; - this._frontMaterial.useColor = true; - this._frontMaterial.texture = texture; - this._frontMaterial.alphaThreshold = this.alphaThreshold; - this._endMaterial.useModel = false; - this._endMaterial.useTexture = true; - this._endMaterial.useColor = true; - this._endMaterial.texture = texture; - this._endMaterial.alphaThreshold = this.alphaThreshold; + this._material.useModel = false; + this._material.useTexture = true; + this._material.useColor = true; + this._material.texture = texture; + this._material.alphaThreshold = this.alphaThreshold; } else { - this._frontMaterial.useModel = true; - this._frontMaterial.useTexture = false; - this._frontMaterial.useColor = false; - this._endMaterial.useModel = true; - this._endMaterial.useTexture = false; - this._endMaterial.useColor = false; + this._material.useModel = true; + this._material.useTexture = false; + this._material.useColor = false; } - - if (!this._material) { - this._updateMaterial(this._frontMaterial); - } - - // Avoid next up mask material to be batch with the exit one - this._endMaterial._hash = -this._frontMaterial._hash; } this.markForRender(true); @@ -437,17 +417,17 @@ let Mask = cc.Class({ markForUpdateRenderData (enable) { if (enable && this.enabledInHierarchy) { - this.node._renderFlag |= RenderFlow.FLAG_UPDATE_RENDER_DATA | RenderFlow.FLAG_POST_UPDATE_RENDER_DATA; + this.node._renderFlag |= RenderFlow.FLAG_UPDATE_RENDER_DATA; } else if (!enable) { - this.node._renderFlag &= ~(RenderFlow.FLAG_UPDATE_RENDER_DATA | RenderFlow.FLAG_POST_UPDATE_RENDER_DATA); + this.node._renderFlag &= ~RenderFlow.FLAG_UPDATE_RENDER_DATA; } }, markForRender (enable) { if (enable && this.enabledInHierarchy) { this.node._renderFlag |= (RenderFlow.FLAG_RENDER | RenderFlow.FLAG_UPDATE_RENDER_DATA | - RenderFlow.FLAG_POST_RENDER | RenderFlow.FLAG_POST_UPDATE_RENDER_DATA); + RenderFlow.FLAG_POST_RENDER); } else if (!enable) { this.node._renderFlag &= ~(RenderFlow.FLAG_RENDER | RenderFlow.FLAG_POST_RENDER); @@ -456,7 +436,7 @@ let Mask = cc.Class({ disableRender () { this.node._renderFlag &= ~(RenderFlow.FLAG_RENDER | RenderFlow.FLAG_UPDATE_RENDER_DATA | - RenderFlow.FLAG_POST_RENDER | RenderFlow.FLAG_POST_UPDATE_RENDER_DATA); + RenderFlow.FLAG_POST_RENDER); }, }); diff --git a/cocos2d/core/renderer/webgl/assemblers/mask-assembler.js b/cocos2d/core/renderer/webgl/assemblers/mask-assembler.js index 2d2a848836..543c83d1f9 100644 --- a/cocos2d/core/renderer/webgl/assemblers/mask-assembler.js +++ b/cocos2d/core/renderer/webgl/assemblers/mask-assembler.js @@ -24,13 +24,32 @@ ****************************************************************************/ const StencilManager = require('../stencil-manager'); +const Node = require('../../../CCNode'); const Mask = require('../../../components/CCMask'); +const Graphics = require('../../../graphics/graphics'); const RenderFlow = require('../../render-flow'); const spriteAssembler = require('./sprite/simple'); const graphicsAssembler = require('./graphics'); let _stencilMgr = StencilManager.sharedManager; +// for nested mask, we might need multiple graphics component to avoid data conflict +let _graphicsPool = []; + +function getGraphics () { + let graphics = _graphicsPool.pop(); + + if (!graphics) { + let graphicsNode = new Node(); + graphics = graphicsNode.addComponent(Graphics); + graphics._activateMaterial(); + graphics.lineWidth = 0; + graphics.rect(0, 0, cc.visibleRect.width, cc.visibleRect.height); + graphics.fill(); + graphicsAssembler.updateRenderData(graphics); + } + return graphics; +} let maskFrontAssembler = { updateRenderData (mask) { @@ -45,7 +64,6 @@ let maskFrontAssembler = { } let renderData = mask._renderData; - mask._material = mask._frontMaterial; if (mask._type === Mask.Type.IMAGE_STENCIL) { if (mask.spriteFrame) { let size = mask.node._contentSize; @@ -53,7 +71,7 @@ let maskFrontAssembler = { renderData.updateSizeNPivot(size.width, size.height, anchor.x, anchor.y); renderData.dataLength = 4; spriteAssembler.updateRenderData(mask); - renderData.material = mask.getMaterial(); + renderData.material = mask._material; } else { mask._material = null; @@ -70,10 +88,19 @@ let maskFrontAssembler = { if (mask._type !== Mask.Type.IMAGE_STENCIL || mask.spriteFrame) { // HACK: Must push mask after batch, so we can only put this logic in fillVertexBuffer or fillIndexBuffer _stencilMgr.pushMask(mask); + _stencilMgr.clear(); + + mask._clearGraphics = getGraphics(); + graphicsAssembler.fillBuffers(mask._clearGraphics, renderer); + + _stencilMgr.enterLevel(); // vertex buffer + renderer.node = mask.node; + renderer.material = mask._material; if (mask._type === Mask.Type.IMAGE_STENCIL) { spriteAssembler.fillBuffers(mask, renderer); + renderer._flush(); } else { graphicsAssembler.fillBuffers(mask._graphics, renderer); @@ -85,43 +112,17 @@ let maskFrontAssembler = { }; let maskEndAssembler = { - updateRenderData (mask) { - if (mask._type === Mask.Type.IMAGE_STENCIL && !mask.spriteFrame) { - mask._material = null; - } - else { - mask._material = mask._endMaterial; - } - let material = mask._material; - - if (mask._type === Mask.Type.IMAGE_STENCIL) { - let data = mask._renderData; - data.material = material; - } - else { - let datas = mask._graphics._impl._renderDatas; - for (let i = 0; i < datas.length; i++) { - datas[i].material = material; - } - } - }, - fillBuffers (mask, renderer) { // Invalid state if (mask._type !== Mask.Type.IMAGE_STENCIL || mask.spriteFrame) { // HACK: Must pop mask after batch, so we can only put this logic in fillBuffers - _stencilMgr.popMask(); + _stencilMgr.exitMask(); - // vertex buffer - if (mask._type === Mask.Type.IMAGE_STENCIL) { - spriteAssembler.fillBuffers(mask, renderer); - } - else { - graphicsAssembler.fillBuffers(mask._graphics, renderer); - } + _graphicsPool.push(mask._clearGraphics); + mask._clearGraphics = null; } - mask.node._renderFlag |= RenderFlow.FLAG_UPDATE_RENDER_DATA | RenderFlow.FLAG_POST_UPDATE_RENDER_DATA; + mask.node._renderFlag |= RenderFlow.FLAG_UPDATE_RENDER_DATA; } }; diff --git a/cocos2d/core/renderer/webgl/stencil-manager.js b/cocos2d/core/renderer/webgl/stencil-manager.js index 5e0c41776c..9806f172ab 100644 --- a/cocos2d/core/renderer/webgl/stencil-manager.js +++ b/cocos2d/core/renderer/webgl/stencil-manager.js @@ -30,12 +30,14 @@ const gfx = renderEngine.gfx; var Stage = cc.Enum({ // Stencil disabled DISABLED: 0, + // Clear stencil buffer + CLEAR: 1, // Entering a new level, should handle new stencil - ENTER_LEVEL: 1, - // In stencil - ENABLED: 2, + ENTER_LEVEL: 2, + // In content + ENABLED: 3, // Exiting a level, should restore old stencil or disable - EXIT_LEVEL: 3, + EXIT_LEVEL: 4, }); function StencilManager () { @@ -86,18 +88,26 @@ StencilManager.prototype = { stencilMask = ref; } failOp = gfx.STENCIL_OP_KEEP; - writeMask = 0; + writeMask = this.getWriteMask(); } else { - func = gfx.DS_FUNC_NEVER; - failOp = gfx.STENCIL_OP_REPLACE; - - if (this.stage === Stage.ENTER_LEVEL) { + if (this.stage === Stage.CLEAR) { + mask = this._maskStack[this._maskStack.length - 1]; + func = gfx.DS_FUNC_NEVER; + ref = this.getWriteMask(); + stencilMask = ref; + writeMask = ref; + failOp = mask.inverted ? gfx.STENCIL_OP_REPLACE : gfx.STENCIL_OP_ZERO; + } + else if (this.stage === Stage.ENTER_LEVEL) { + mask = this._maskStack[this._maskStack.length - 1]; this.stage = Stage.ENABLED; // Fill stencil mask - ref = this.getStencilRef(); - stencilMask = this.getWriteMask(); - writeMask = stencilMask; + func = gfx.DS_FUNC_NEVER; + ref = this.getWriteMask(); + stencilMask = ref; + writeMask = ref; + failOp = mask.inverted ? gfx.STENCIL_OP_ZERO : gfx.STENCIL_OP_REPLACE; } else if (this.stage === Stage.EXIT_LEVEL) { // Pop mask after getting the correct stencil mask @@ -108,9 +118,11 @@ StencilManager.prototype = { this.stage = Stage.ENABLED; } // Clear stencil mask - ref = 0; - stencilMask = this.getExitWriteMask(); - writeMask = stencilMask; + func = gfx.DS_FUNC_EQUAL; + ref = this.getExitWriteMask(); + stencilMask = ref; + writeMask = ref; + failOp = gfx.STENCIL_OP_KEEP; } } @@ -127,10 +139,17 @@ StencilManager.prototype = { cc.errorID(9000, this._maxLevel); } this._maskStack.push(mask); + }, + + clear () { + this.stage = Stage.CLEAR; + }, + + enterLevel () { this.stage = Stage.ENTER_LEVEL; }, - popMask () { + exitMask () { if (this._maskStack.length === 0) { cc.errorID(9001); } From bd6cceaf6be52f5fd3f3c46a35c67320004cbdca Mon Sep 17 00:00:00 2001 From: ColinCollins <35832931+ColinCollins@users.noreply.github.com> Date: Tue, 28 Aug 2018 10:18:04 +0800 Subject: [PATCH 45/53] remove the emoji (#3148) --- EngineErrorMap.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/EngineErrorMap.md b/EngineErrorMap.md index 7a3ca2ffbc..9e9f3d562a 100644 --- a/EngineErrorMap.md +++ b/EngineErrorMap.md @@ -230,7 +230,7 @@ cc.spriteFrameCache is removed, please use cc.loader to load and cache sprite fr ### 1405 -The '%s' will be removed in v2.0, please use '%s' instead. 😥 +The '%s' will be removed in v2.0, please use '%s' instead. ### 1500 @@ -1098,7 +1098,7 @@ Unknown editor property '%s' in class '%s'. ### 3603 -Use 'cc.Float' or 'cc.Integer' instead of 'cc.Number' please. 😂 +Use 'cc.Float' or 'cc.Integer' instead of 'cc.Number' please. ### 3604 @@ -1303,7 +1303,7 @@ Failed to construct a dummy instance of the "%s" class using `new` behind the sc ### 3653 Please do not specifiy "default" attribute in decorator of "%s" property in "%s" class. -Default value must be initialized at their declaration: 😰 +Default value must be initialized at their declaration: ``` // Before: @property({ @@ -1320,7 +1320,7 @@ value = 0; // <-- ### 3654 -Please specifiy a default value for "%s" property at its declaration: 😰 +Please specifiy a default value for "%s" property at its declaration: ``` // Before: @property(...) From ea7803f874e062566968f4ac6d5c1283367c500a Mon Sep 17 00:00:00 2001 From: ColinCollins <35832931+ColinCollins@users.noreply.github.com> Date: Tue, 28 Aug 2018 10:51:56 +0800 Subject: [PATCH 46/53] modify the path.baseName() (#3142) * modify the path.baseName() judge the adaptation of the file basename * add path.basename test --- cocos2d/core/utils/CCPath.js | 4 ++-- test/qunit/unit-es5/test-path.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/cocos2d/core/utils/CCPath.js b/cocos2d/core/utils/CCPath.js index d3749c52fe..d0089bfe45 100644 --- a/cocos2d/core/utils/CCPath.js +++ b/cocos2d/core/utils/CCPath.js @@ -95,8 +95,8 @@ cc.path = /** @lends cc.path# */{ basename: function (pathStr, extname) { var index = pathStr.indexOf("?"); if (index > 0) pathStr = pathStr.substring(0, index); - var reg = /(\/|\\\\)([^(\/|\\\\)]+)$/g; - var result = reg.exec(pathStr.replace(/(\/|\\\\)$/, "")); + var reg = /(\/|\\)([^\/\\]+)$/g; + var result = reg.exec(pathStr.replace(/(\/|\\)$/, "")); if (!result) return null; var baseName = result[2]; if (extname && pathStr.substring(pathStr.length - extname.length).toLowerCase() === extname.toLowerCase()) diff --git a/test/qunit/unit-es5/test-path.js b/test/qunit/unit-es5/test-path.js index 62b9f7a21d..5b7b488b20 100644 --- a/test/qunit/unit-es5/test-path.js +++ b/test/qunit/unit-es5/test-path.js @@ -10,3 +10,18 @@ test('dirname', function () { ok(cc.path.dirname('aa/bb/.github/.gitignore') === 'aa/bb/.github', 'get success'); }); + +test('basename', function () { + + ok(cc.path.basename('aa/bb/cc.js', '.js') === 'cc', 'get success'); + ok(cc.path.basename('aa/bb/cc_cc.js','.js') === 'cc_cc', 'get success'); + ok(cc.path.basename('aa/bb/cc/') === 'cc', 'get success'); + ok(cc.path.basename('D:\\aa\\bb\\cc') === 'cc', 'get success'); + ok(cc.path.basename('aa/bb/cc(cc).js', '.js') === 'cc(cc)', 'get success'); + ok(cc.path.basename('aa/bb/cc[cc].js', '.js') === 'cc[cc]', 'get success'); + ok(cc.path.basename('aa/bb/cc.js/ee.js', '.js') === 'ee', 'get success'); + ok(cc.path.basename('aa/bb/.github') === '.github', 'get success'); + // ios only, and linux not suggest + ok(cc.path.basename('aa/bb/cc|cc.js', '.js') === 'cc|cc', 'get success'); + +}); \ No newline at end of file From 785fe0353cd763f265483de91c0c4ff9f6a6c77c Mon Sep 17 00:00:00 2001 From: PP Date: Tue, 28 Aug 2018 15:47:40 +0800 Subject: [PATCH 47/53] fix editbox input matrix updating in camera (#3153) --- .../core/components/editbox/CCEditBoxImpl.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/cocos2d/core/components/editbox/CCEditBoxImpl.js b/cocos2d/core/components/editbox/CCEditBoxImpl.js index c0f328cc32..b499d6e583 100644 --- a/cocos2d/core/components/editbox/CCEditBoxImpl.js +++ b/cocos2d/core/components/editbox/CCEditBoxImpl.js @@ -42,6 +42,7 @@ let FOCUS_DELAY_FIREFOX = 0; let math = cc.vmath; let _matrix = math.mat4.create(); +let _matrix_temp = math.mat4.create(); let _vec3 = cc.v3(); // polyfill @@ -360,18 +361,30 @@ let EditBoxImpl = cc.Class({ _vec3.y = -node._anchorPoint.y * contentSize.height; math.mat4.translate(_matrix, _matrix, _vec3); + + let camera; + // can't find camera in editor + if (CC_EDITOR) { + camera = cc.Camera.main; + } + else { + camera = cc.Camera.findCamera(node); + } + + camera.getWorldToCameraMatrix(_matrix_temp); + math.mat4.mul(_matrix_temp, _matrix_temp, _matrix); scaleX /= dpr; scaleY /= dpr; let container = cc.game.container; - let a = _matrix.m00 * scaleX, b = _matrix.m01, c = _matrix.m04, d = _matrix.m05 * scaleY; + let a = _matrix_temp.m00 * scaleX, b = _matrix.m01, c = _matrix.m04, d = _matrix_temp.m05 * scaleY; let offsetX = container && container.style.paddingLeft && parseInt(container.style.paddingLeft); offsetX += viewport.x / dpr; let offsetY = container && container.style.paddingBottom && parseInt(container.style.paddingBottom); offsetY += viewport.y / dpr; - let tx = _matrix.m12 * scaleX + offsetX, ty = _matrix.m13 * scaleY + offsetY; + let tx = _matrix_temp.m12 * scaleX + offsetX, ty = _matrix_temp.m13 * scaleY + offsetY; if (polyfill.zoomInvalid) { this._updateSize(this._size.width * a, this._size.height * d); From 6a39c383b16563d6e1b1d61b2acf5ef81d514e84 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Tue, 28 Aug 2018 17:17:51 +0800 Subject: [PATCH 48/53] Fix motion streak lazy loading (#3155) --- cocos2d/core/components/CCMotionStreak.js | 32 ++++++++++++++++------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/cocos2d/core/components/CCMotionStreak.js b/cocos2d/core/components/CCMotionStreak.js index 5b161364be..b577013a2b 100644 --- a/cocos2d/core/components/CCMotionStreak.js +++ b/cocos2d/core/components/CCMotionStreak.js @@ -26,6 +26,7 @@ const RenderComponent = require('../components/CCRenderComponent'); const SpriteMaterial = require('../renderer/render-engine').SpriteMaterial; +const textureUtil = require('../utils/texture-util'); /** * !#en @@ -159,13 +160,12 @@ var MotionStreak = cc.Class({ this._texture = value; - if (!value) { + if (!value || !value.loaded) { this.disableRender(); + this._ensureLoadTexture(); } else { - this.markForRender(true); - this.markForUpdateRenderData(true); - this._activateMaterial(true); + this._activateMaterial(); } }, type: cc.Texture2D, @@ -220,6 +220,7 @@ var MotionStreak = cc.Class({ if (!this._texture || !this._texture.loaded) { this.disableRender(); + this._ensureLoadTexture(); } else { this._activateMaterial(); @@ -227,18 +228,29 @@ var MotionStreak = cc.Class({ this.reset(); }, - _activateMaterial (force) { + _ensureLoadTexture: function () { + if (this._texture && !this._texture.loaded) { + // load exists texture + let self = this; + textureUtil.postLoadTexture(this._texture, function () { + self._activateMaterial(); + }); + } + }, + + _activateMaterial () { let material = this._material; if (!material) { material = this._material = new SpriteMaterial(); material.useColor = false; } - else if (!force) { - return; - } - material.texture = this._texture; - this._updateMaterial(material); + if (this._texture && this._texture.loaded) { + material.texture = this._texture; + this._updateMaterial(material); + this.markForRender(true); + this.markForUpdateRenderData(true); + } }, onFocusInEditor: CC_EDITOR && function () { From 092ee866a14f794acbdf51f8e6d43313d14e4f1e Mon Sep 17 00:00:00 2001 From: Knox Date: Tue, 28 Aug 2018 17:50:37 +0800 Subject: [PATCH 49/53] fix _finishCallback did not clean up bug (#3154) --- cocos2d/audio/CCAudioEngine.js | 1 + 1 file changed, 1 insertion(+) diff --git a/cocos2d/audio/CCAudioEngine.js b/cocos2d/audio/CCAudioEngine.js index 14d8026894..7a6b5324ac 100644 --- a/cocos2d/audio/CCAudioEngine.js +++ b/cocos2d/audio/CCAudioEngine.js @@ -35,6 +35,7 @@ let _url2id = {}; let _audioPool = []; let recycleAudio = function (audio) { + audio._finishCallback = null; if (_audioPool.length < 32) { audio.off('ended'); audio.off('stop'); From b73fadc2398afa5f7fb3a808e9595467fb7ac205 Mon Sep 17 00:00:00 2001 From: ColinCollins <35832931+ColinCollins@users.noreply.github.com> Date: Wed, 29 Aug 2018 13:49:44 +0800 Subject: [PATCH 50/53] fixed the layout sequence lost order problem (#3156) --- cocos2d/core/components/CCLayout.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/cocos2d/core/components/CCLayout.js b/cocos2d/core/components/CCLayout.js index c54cbec215..ad0c8b7ff9 100644 --- a/cocos2d/core/components/CCLayout.js +++ b/cocos2d/core/components/CCLayout.js @@ -537,20 +537,22 @@ var Layout = cc.Class({ for (var i = 0; i < children.length; ++i) { var child = children[i]; + let childScaleX = Math.abs(child.scaleX); + let childScaleY = Math.abs(child.scaleY); if (!child.activeInHierarchy) { continue; } //for resizing children if (this._resize === ResizeMode.CHILDREN) { - child.width = newChildWidth / child.scaleX; + child.width = newChildWidth / childScaleX; if (this.type === Type.GRID) { - child.height = this.cellSize.height / child.scaleY; + child.height = this.cellSize.height / childScaleY; } } var anchorX = child.anchorX; - var childBoundingBoxWidth = child.width * child.scaleX; - var childBoundingBoxHeight = child.height * child.scaleY; + var childBoundingBoxWidth = child.width * childScaleX; + var childBoundingBoxHeight = child.height * childScaleY; if (secondMaxHeight > tempMaxHeight) { tempMaxHeight = secondMaxHeight; @@ -633,7 +635,7 @@ var Layout = cc.Class({ var child = children[i]; if (child.activeInHierarchy) { activeChildCount++; - newHeight += child.height * child.scaleY; + newHeight += child.height * Math.abs(child.scaleY); } } @@ -681,21 +683,23 @@ var Layout = cc.Class({ for (var i = 0; i < children.length; ++i) { var child = children[i]; + let childScaleX = Math.abs(child.scaleX); + let childScaleY = Math.abs(child.scaleY); if (!child.activeInHierarchy) { continue; } //for resizing children if (this.resizeMode === ResizeMode.CHILDREN) { - child.height = newChildHeight / child.scaleY; + child.height = newChildHeight / childScaleY; if (this.type === Type.GRID) { - child.width = this.cellSize.width / child.scaleX; + child.width = this.cellSize.width / childScaleX; } } var anchorY = child.anchorY; - var childBoundingBoxWidth = child.width * child.scaleX; - var childBoundingBoxHeight = child.height * child.scaleY; + var childBoundingBoxWidth = child.width * childScaleX; + var childBoundingBoxHeight = child.height * childScaleY; if (secondMaxWidth > tempMaxWidth) { tempMaxWidth = secondMaxWidth; @@ -821,7 +825,7 @@ var Layout = cc.Class({ } var fnPositionY = function (child, topOffset, row) { - return bottomBoundaryOfLayout + sign * (topOffset + child.anchorY * child.height * child.scaleY + paddingY + row * this.spacingY); + return bottomBoundaryOfLayout + sign * (topOffset + child.anchorY * child.height * Math.abs(child.scaleY) + paddingY + row * this.spacingY); }.bind(this); @@ -862,7 +866,7 @@ var Layout = cc.Class({ } var fnPositionX = function (child, leftOffset, column) { - return leftBoundaryOfLayout + sign * (leftOffset + child.anchorX * child.width * child.scaleX + paddingX + column * this.spacingX); + return leftBoundaryOfLayout + sign * (leftOffset + child.anchorX * child.width * Math.abs(child.scaleX) + paddingX + column * this.spacingX); }.bind(this); var newWidth = 0; @@ -910,7 +914,7 @@ var Layout = cc.Class({ var child = children[i]; if (child.activeInHierarchy) { activeChildCount++; - newWidth += child.width * child.scaleX; + newWidth += child.width * Math.abs(child.scaleX); } } newWidth += (activeChildCount - 1) * this.spacingX + this.paddingLeft + this.paddingRight; From 942a4bc116fc83637a246912ec9560180f53569f Mon Sep 17 00:00:00 2001 From: PP Date: Wed, 29 Aug 2018 13:54:09 +0800 Subject: [PATCH 51/53] exact fit child nodes in editBox when resize (#3157) --- cocos2d/core/components/editbox/CCEditBox.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/cocos2d/core/components/editbox/CCEditBox.js b/cocos2d/core/components/editbox/CCEditBox.js index a5aad021e9..e6e7ebdae1 100644 --- a/cocos2d/core/components/editbox/CCEditBox.js +++ b/cocos2d/core/components/editbox/CCEditBox.js @@ -366,6 +366,7 @@ let EditBox = cc.Class({ _init () { this._createBackgroundSprite(); this._createLabels(); + this.node.on(cc.Node.EventType.SIZE_CHANGED, this._resizeChildNodes, this); let impl = this._impl = new EditBoxImpl(); @@ -494,6 +495,25 @@ let EditBox = cc.Class({ } }, + _resizeChildNodes () { + let textLabelNode = this._textLabel.node, + placeholderLabelNode = this._placeholderLabel.node, + backgroundNode = this._background.node; + + textLabelNode.x = -this.node.width/2; + textLabelNode.y = this.node.height/2; + textLabelNode.width = this.node.width; + textLabelNode.height = this.node.height; + + placeholderLabelNode.x = -this.node.width/2; + placeholderLabelNode.y = this.node.height/2; + placeholderLabelNode.width = this.node.width; + placeholderLabelNode.height = this.node.height; + + backgroundNode.width = this.node.width; + backgroundNode.height = this.node.height; + }, + _showLabels () { let displayText = this._textLabel.string; this._textLabel.node.active = displayText !== ''; From e57e6af87f5755d6a5c5696aec4b1d58a7b00e6c Mon Sep 17 00:00:00 2001 From: PP Date: Wed, 29 Aug 2018 16:17:44 +0800 Subject: [PATCH 52/53] fix actionManager can't remove all actions (#3159) --- cocos2d/actions/CCActionManager.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cocos2d/actions/CCActionManager.js b/cocos2d/actions/CCActionManager.js index 04566add6e..742fd92ad0 100644 --- a/cocos2d/actions/CCActionManager.js +++ b/cocos2d/actions/CCActionManager.js @@ -145,11 +145,16 @@ cc.ActionManager.prototype = { */ removeAllActions:function () { var locTargets = this._arrayTargets; - for (var i = 0; i < locTargets.length; i++) { - var element = locTargets[i]; + + // RemoveAllActionsFromTarget changes the length of array _arrayTargets. + // So we iterate on the locTargets_clone instead of locTargets. + var locTargets_clone = cc.js.array.copy(locTargets); + for (var i = 0; i < locTargets_clone.length; i++) { + var element = locTargets_clone[i]; if (element) this.removeAllActionsFromTarget(element.target, true); } + locTargets_clone.length = 0; }, /** * !#en From 1fbb643047877fb90e74e6fb1a65b7a3f99e78dd Mon Sep 17 00:00:00 2001 From: PP Date: Wed, 29 Aug 2018 17:35:30 +0800 Subject: [PATCH 53/53] fix actionManager can't remove all actions again (#3160) --- cocos2d/actions/CCActionManager.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/cocos2d/actions/CCActionManager.js b/cocos2d/actions/CCActionManager.js index 742fd92ad0..e634467081 100644 --- a/cocos2d/actions/CCActionManager.js +++ b/cocos2d/actions/CCActionManager.js @@ -145,16 +145,13 @@ cc.ActionManager.prototype = { */ removeAllActions:function () { var locTargets = this._arrayTargets; - - // RemoveAllActionsFromTarget changes the length of array _arrayTargets. - // So we iterate on the locTargets_clone instead of locTargets. - var locTargets_clone = cc.js.array.copy(locTargets); - for (var i = 0; i < locTargets_clone.length; i++) { - var element = locTargets_clone[i]; + for (var i = 0; i < locTargets.length; i++) { + var element = locTargets[i]; if (element) - this.removeAllActionsFromTarget(element.target, true); + this._putElement(element); } - locTargets_clone.length = 0; + this._arrayTargets.length = 0; + this._hashTargets = js.createMap(true); }, /** * !#en