From cf536cc315c156afeb1f00ff6e99c1a9709126d1 Mon Sep 17 00:00:00 2001 From: 2youyouo2 <501251991@qq.com> Date: Fri, 24 Mar 2017 12:04:58 +0800 Subject: [PATCH 1/6] add camera --- cocos2d/core/camera/CCCamera.js | 126 ++++++++++++++++++ cocos2d/core/camera/CCSGCameraNode.js | 76 +++++++++++ cocos2d/core/collider/CCCollisionManager.js | 9 ++ cocos2d/core/index.js | 1 + cocos2d/core/physics/CCPhysicsDebugDraw.js | 90 ------------- cocos2d/core/physics/CCPhysicsManager.js | 13 +- cocos2d/core/physics/CCPhysicsTypes.js | 2 +- .../physics/platform/CCPhysicsDebugDraw.js | 4 + cocos2d/core/sprites/CCScale9Sprite.js | 26 ++-- gulpfile.js | 1 + 10 files changed, 244 insertions(+), 104 deletions(-) create mode 100644 cocos2d/core/camera/CCCamera.js create mode 100644 cocos2d/core/camera/CCSGCameraNode.js delete mode 100644 cocos2d/core/physics/CCPhysicsDebugDraw.js diff --git a/cocos2d/core/camera/CCCamera.js b/cocos2d/core/camera/CCCamera.js new file mode 100644 index 0000000000..bf0f7f999c --- /dev/null +++ b/cocos2d/core/camera/CCCamera.js @@ -0,0 +1,126 @@ +/**************************************************************************** + Copyright (c) 2013-2016 Chukong Technologies Inc. + + http://www.cocos.com + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Chukong Aipu reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +let CameraNode; +if (!CC_JSB) { + CameraNode = require('./CCSGCameraNode'); +} +else { + CameraNode = cc.CameraNode; +} + +_ccsg.CameraNode = CameraNode; + +let Camera = cc.Class({ + name: 'cc.Camera', + extends: cc._RendererUnderSG, + + editor: CC_EDITOR && { + menu: 'i18n:MAIN_MENU.component.others/Camera', + }, + + properties: { + _targets: { + default: function () { + return []; + }, + type: cc.Node, + visible: true + }, + + zoomRatio: 1 + }, + + _createSgNode: function () { + return new CameraNode(); + }, + + _initSgNode: function () {}, + + _addSgTargetInSg: function (target) { + if (target instanceof cc.Node) { + this._sgNode.addTarget(target._sgNode); + } + else if (target instanceof _ccsg.Node) { + this._sgNode.addTarget(target); + } + }, + + _removeTargetInSg: function (target) { + if (target instanceof cc.Node) { + this._sgNode.removeTarget(target._sgNode); + } + else if (target instanceof _ccsg.Node) { + this._sgNode.removeTarget(target); + } + }, + + onEnable: function () { + let targets = this._targets; + for (let i = 0, l = targets.length; i < l; i++) { + this._addSgTargetInSg(targets[i]); + } + }, + + onDisable: function () { + let targets = this._targets; + for (let i = 0, l = targets.length; i < l; i++) { + this._removeTargetInSg(targets[i]); + } + }, + + addTarget: function (target) { + if (this._targets.indexOf(target) !== -1) { + return; + } + + this._addSgTargetInSg(target); + this._targets.push(target); + }, + + removeTarget: function (target) { + if (this._targets.indexOf(target) === -1) { + return; + } + + this._removeTargetInSg(target); + cc.js.array.remove(this._targets, target); + }, + + getTargets: function () { + return this._targets; + }, + + lateUpdate: !CC_EDITOR && function () { + let center = cc.visibleRect.center; + let pos = this.node.convertToWorldSpaceAR(cc.Vec2.ZERO); + let zoomRatio = this.zoomRatio; + pos.x = center.x - pos.x * zoomRatio; + pos.y = center.y - pos.y * zoomRatio; + this._sgNode.setTransform(pos, zoomRatio); + } +}); + +module.exports = cc.Camera = Camera; diff --git a/cocos2d/core/camera/CCSGCameraNode.js b/cocos2d/core/camera/CCSGCameraNode.js new file mode 100644 index 0000000000..2e97b1387a --- /dev/null +++ b/cocos2d/core/camera/CCSGCameraNode.js @@ -0,0 +1,76 @@ +let tempMatrix = new cc.math.Matrix4(); + +let CameraNode = _ccsg.Node.extend({ + ctor: function () { + this._super(); + + this._mat = new cc.math.Matrix4(); + this._mat.identity(); + }, + + setTransform: function (vec, zoom) { + let mat = this._mat; + + // reset matrix + tempMatrix.identity(); + mat.identity(); + + // set zoom + tempMatrix.mat[0] = zoom; + tempMatrix.mat[5] = zoom; + tempMatrix.mat[10] = zoom; + + // set x,y + tempMatrix.mat[12] = vec.x; + tempMatrix.mat[13] = vec.y; + + mat.multiply(tempMatrix); + }, + + addTarget: function (target) { + if (target.__cameraInfo) return; + + target.__cameraInfo = { + sgCameraNode: this, + originVisit: target.visit + }; + + target.visit = this._visit; + }, + + removeTarget: function (target) { + let info = target.__cameraInfo; + if (!info) return; + + target.visit = info.originVisit; + target.__cameraInfo = undefined; + }, + + _visit: function (parent) { + let info = this.__cameraInfo; + let sgCameraNode = info.sgCameraNode; + + let beforeVisitCmd = new cc.CustomRenderCmd(sgCameraNode, sgCameraNode._onBeforeVisit); + let afterVisitCmd = new cc.CustomRenderCmd(sgCameraNode, sgCameraNode._onAfterVisit); + + cc.renderer.pushRenderCommand(beforeVisitCmd); + info.originVisit.call(this, parent); + cc.renderer.pushRenderCommand(afterVisitCmd); + }, + + _onBeforeVisit: function () { + cc.renderer._breakBatch(); + + cc.math.glMatrixMode(cc.math.KM_GL_PROJECTION) + cc.current_stack.push(); + cc.current_stack.top.multiply(this._mat); + }, + + _onAfterVisit: function () { + cc.math.glMatrixMode(cc.math.KM_GL_PROJECTION) + cc.current_stack.pop(); + }, + +}); + +module.exports = CameraNode; diff --git a/cocos2d/core/collider/CCCollisionManager.js b/cocos2d/core/collider/CCCollisionManager.js index 9a16b7bb6f..d748778aba 100644 --- a/cocos2d/core/collider/CCCollisionManager.js +++ b/cocos2d/core/collider/CCCollisionManager.js @@ -308,6 +308,15 @@ var CollisionManager = cc.Class({ } }, + attachDebugDrawToCamera: function (camera) { + if (!this._debugDrawer) return; + camera.addTarget(this._debugDrawer); + }, + detachDebugDrawFromCamera: function (camera) { + if (!this._debugDrawer) return; + camera.removeTarget(this._debugDrawer); + }, + onNodeGroupChanged: function (event) { var node = event.currentTarget; var colliders = node.getComponents(cc.Collider); diff --git a/cocos2d/core/index.js b/cocos2d/core/index.js index 1fca2325be..e080d7001a 100644 --- a/cocos2d/core/index.js +++ b/cocos2d/core/index.js @@ -34,6 +34,7 @@ if (!CC_EDITOR || !Editor.isMainProcess) { require('./graphics'); require('./collider'); require('./physics'); + require('./camera/CCCamera'); } require('./base-ui/CCWidgetManager'); diff --git a/cocos2d/core/physics/CCPhysicsDebugDraw.js b/cocos2d/core/physics/CCPhysicsDebugDraw.js deleted file mode 100644 index 784d23b3a2..0000000000 --- a/cocos2d/core/physics/CCPhysicsDebugDraw.js +++ /dev/null @@ -1,90 +0,0 @@ - -var CC_PTM_RATIO = cc.PhysicsManager.CC_PTM_RATIO; -var PhysicsDebugDraw = cc.Class({ - name: 'cc.PhysicsDebugDraw', - mixins: [b2.Draw], - - ctor: function () { - this._drawer = new _ccsg.GraphicsNode(); - this._drawer.retain(); - }, - - AddDrawerToNode: function (node) { - this._drawer.removeFromParent(); - node.addChild(this._drawer); - }, - - ClearDraw: function () { - this._drawer.clear(); - }, - - _DrawPolygon: function (vertices, vertexCount) { - var drawer = this._drawer; - - for (var i=0; i> 31 || // All outside left - ((vr.x-x0) & (vr.x-x1) & (vr.x-x2) & (vr.x-x3)) >> 31 || // All outside right - ((y0-vb.y) & (y1-vb.y) & (y2-vb.y) & (y3-vb.y)) >> 31 || // All outside bottom - ((vt.y-y0) & (vt.y-y1) & (vt.y-y2) & (vt.y-y3)) >> 31) // All outside top - { - this._renderCmd._needDraw = false; - } - else { + // var vert = this._isTriangle ? this._rawVerts : this._vertices, + // x0 = vert[cornerId[0]], x1 = vert[cornerId[1]], x2 = vert[cornerId[2]], x3 = vert[cornerId[3]], + // y0 = vert[cornerId[0] + 1], y1 = vert[cornerId[1] + 1], y2 = vert[cornerId[2] + 1], y3 = vert[cornerId[3] + 1]; + // if (((x0-vl.x) & (x1-vl.x) & (x2-vl.x) & (x3-vl.x)) >> 31 || // All outside left + // ((vr.x-x0) & (vr.x-x1) & (vr.x-x2) & (vr.x-x3)) >> 31 || // All outside right + // ((y0-vb.y) & (y1-vb.y) & (y2-vb.y) & (y3-vb.y)) >> 31 || // All outside bottom + // ((vt.y-y0) & (vt.y-y1) & (vt.y-y2) & (vt.y-y3)) >> 31) // All outside top + // { + // this._renderCmd._needDraw = false; + // } + // else { this._renderCmd._needDraw = true; - } + // } } else { var bb = this._renderCmd._currentRegion, diff --git a/gulpfile.js b/gulpfile.js index ce4b17d761..a08f1bb955 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -95,6 +95,7 @@ var jsbSkipModules = [ '../../cocos2d/core/physics/platform/CCPhysicsAABBQueryCallback.js', '../../cocos2d/core/physics/platform/CCPhysicsRayCastCallback.js', '../../cocos2d/core/physics/platform/CCPhysicsContactListner.js', + '../../cocos2d/core/camera/CCSGCameraNode.js', ]; gulp.task('build-jsb-extends-dev', function (done) { From b12914197c2f75666bccf6e400f322db8233965b Mon Sep 17 00:00:00 2001 From: 2youyouo2 <501251991@qq.com> Date: Mon, 27 Mar 2017 10:34:35 +0800 Subject: [PATCH 2/6] refine camera --- DebugInfos.js | 2 + cocos2d/core/camera/CCCamera.js | 80 ++++++++++++++++++++------ cocos2d/core/camera/CCSGCameraNode.js | 49 +++++++--------- cocos2d/core/renderer/RendererWebGL.js | 4 +- cocos2d/core/sprites/CCScale9Sprite.js | 2 +- jsb/jsb-etc.js | 3 +- 6 files changed, 90 insertions(+), 50 deletions(-) diff --git a/DebugInfos.js b/DebugInfos.js index 2d2a0c6aa9..941771490e 100644 --- a/DebugInfos.js +++ b/DebugInfos.js @@ -579,6 +579,8 @@ if (CC_DEV) { "8105": "cocos2d: cc.shaderCache._loadDefaultShader, error shader type", //_loadDefaultShader //Physics: 8200 "8200": "Please set node\'s active instead of rigidbody\'s enabled.", //cc.RigidBody.enabled + //Camera: 8300 + "8300": "Should only one camera be enabled, please check your project.", //cc.Camera.enabled }; cc._LogInfos = logs; } diff --git a/cocos2d/core/camera/CCCamera.js b/cocos2d/core/camera/CCCamera.js index bf0f7f999c..388126a54c 100644 --- a/cocos2d/core/camera/CCCamera.js +++ b/cocos2d/core/camera/CCCamera.js @@ -23,15 +23,14 @@ THE SOFTWARE. ****************************************************************************/ -let CameraNode; if (!CC_JSB) { - CameraNode = require('./CCSGCameraNode'); -} -else { - CameraNode = cc.CameraNode; + require('./CCSGCameraNode'); } -_ccsg.CameraNode = CameraNode; +let ONE_DEGREE = Math.PI / 180; + +let cameraExists = false; +let tempTransform = cc.affineTransformMake(); let Camera = cc.Class({ name: 'cc.Camera', @@ -43,18 +42,16 @@ let Camera = cc.Class({ properties: { _targets: { - default: function () { - return []; - }, + default: [], type: cc.Node, visible: true }, - zoomRatio: 1 + zoomRatio: 1, }, _createSgNode: function () { - return new CameraNode(); + return new _ccsg.CameraNode(); }, _initSgNode: function () {}, @@ -78,6 +75,13 @@ let Camera = cc.Class({ }, onEnable: function () { + if (cameraExists) { + cc.warnID('8300'); + return; + } + + cameraExists = true; + let targets = this._targets; for (let i = 0, l = targets.length; i < l; i++) { this._addSgTargetInSg(targets[i]); @@ -85,6 +89,8 @@ let Camera = cc.Class({ }, onDisable: function () { + cameraExists = false; + let targets = this._targets; for (let i = 0, l = targets.length; i < l; i++) { this._removeTargetInSg(targets[i]); @@ -113,13 +119,53 @@ let Camera = cc.Class({ return this._targets; }, - lateUpdate: !CC_EDITOR && function () { - let center = cc.visibleRect.center; - let pos = this.node.convertToWorldSpaceAR(cc.Vec2.ZERO); + calculateCaemraTransformIn: function (transform) { + let node = this.node; + + // calculate world position + let pos = node.convertToWorldSpaceAR(cc.Vec2.ZERO); + + // calculate world rotation + let rotation = node.rotation; + let parent = node.parent; + while (parent){ + rotation += parent.rotation; + parent = parent.parent; + } + + let a = 1, b = 0, c = 0, d = 1; + + // rotation + if (rotation) { + rotation = rotation * ONE_DEGREE; + c = Math.sin(rotation); + d = Math.cos(rotation); + a = d; + b = -c; + } + + // scale let zoomRatio = this.zoomRatio; - pos.x = center.x - pos.x * zoomRatio; - pos.y = center.y - pos.y * zoomRatio; - this._sgNode.setTransform(pos, zoomRatio); + a *= zoomRatio; + b *= zoomRatio; + c *= zoomRatio; + d *= zoomRatio; + + // move camera to center + let center = cc.visibleRect.center; + transform.tx = center.x - (a * pos.x + c * pos.y); + transform.ty = center.y - (b * pos.x + d * pos.y); + + transform.a = a; + transform.b = b; + transform.c = c; + transform.d = d; + }, + + lateUpdate: !CC_EDITOR && function () { + let t = tempTransform; + this.calculateCaemraTransformIn(t); + this._sgNode.setTransform(t.a, t.b, t.c, t.d, t.tx, t.ty); } }); diff --git a/cocos2d/core/camera/CCSGCameraNode.js b/cocos2d/core/camera/CCSGCameraNode.js index 2e97b1387a..32923935d5 100644 --- a/cocos2d/core/camera/CCSGCameraNode.js +++ b/cocos2d/core/camera/CCSGCameraNode.js @@ -1,4 +1,3 @@ -let tempMatrix = new cc.math.Matrix4(); let CameraNode = _ccsg.Node.extend({ ctor: function () { @@ -6,31 +5,26 @@ let CameraNode = _ccsg.Node.extend({ this._mat = new cc.math.Matrix4(); this._mat.identity(); + + this._beforeVisitCmd = new cc.CustomRenderCmd(this, this._onBeforeVisit); + this._afterVisitCmd = new cc.CustomRenderCmd(this, this._onAfterVisit); }, - setTransform: function (vec, zoom) { - let mat = this._mat; + setTransform: function (a, b, c, d, tx, ty) { + let mat = this._mat.mat; - // reset matrix - tempMatrix.identity(); - mat.identity(); - - // set zoom - tempMatrix.mat[0] = zoom; - tempMatrix.mat[5] = zoom; - tempMatrix.mat[10] = zoom; - - // set x,y - tempMatrix.mat[12] = vec.x; - tempMatrix.mat[13] = vec.y; - - mat.multiply(tempMatrix); + mat[0] = a; + mat[1] = b; + mat[4] = c; + mat[5] = d; + mat[12] = tx; + mat[13] = ty; }, addTarget: function (target) { - if (target.__cameraInfo) return; + if (target._cameraInfo) return; - target.__cameraInfo = { + target._cameraInfo = { sgCameraNode: this, originVisit: target.visit }; @@ -39,23 +33,20 @@ let CameraNode = _ccsg.Node.extend({ }, removeTarget: function (target) { - let info = target.__cameraInfo; + let info = target._cameraInfo; if (!info) return; target.visit = info.originVisit; - target.__cameraInfo = undefined; + target._cameraInfo = undefined; }, _visit: function (parent) { - let info = this.__cameraInfo; + let info = this._cameraInfo; let sgCameraNode = info.sgCameraNode; - let beforeVisitCmd = new cc.CustomRenderCmd(sgCameraNode, sgCameraNode._onBeforeVisit); - let afterVisitCmd = new cc.CustomRenderCmd(sgCameraNode, sgCameraNode._onAfterVisit); - - cc.renderer.pushRenderCommand(beforeVisitCmd); + cc.renderer.pushRenderCommand(sgCameraNode._beforeVisitCmd); info.originVisit.call(this, parent); - cc.renderer.pushRenderCommand(afterVisitCmd); + cc.renderer.pushRenderCommand(sgCameraNode._afterVisitCmd); }, _onBeforeVisit: function () { @@ -67,10 +58,12 @@ let CameraNode = _ccsg.Node.extend({ }, _onAfterVisit: function () { + cc.renderer._breakBatch(); + cc.math.glMatrixMode(cc.math.KM_GL_PROJECTION) cc.current_stack.pop(); }, }); -module.exports = CameraNode; +module.exports = _ccsg.CameraNode = CameraNode; diff --git a/cocos2d/core/renderer/RendererWebGL.js b/cocos2d/core/renderer/RendererWebGL.js index 2caa73621f..133506c9de 100644 --- a/cocos2d/core/renderer/RendererWebGL.js +++ b/cocos2d/core/renderer/RendererWebGL.js @@ -268,9 +268,7 @@ cc.rendererWebGL = { if (cmdList.indexOf(cmd) === -1) cmdList.push(cmd); } else { - if (this._renderCmds.indexOf(cmd) === -1) { - this._renderCmds.push(cmd); - } + this._renderCmds.push(cmd); } }, diff --git a/cocos2d/core/sprites/CCScale9Sprite.js b/cocos2d/core/sprites/CCScale9Sprite.js index 696338e6b5..fe80dd8577 100644 --- a/cocos2d/core/sprites/CCScale9Sprite.js +++ b/cocos2d/core/sprites/CCScale9Sprite.js @@ -1426,7 +1426,7 @@ cc.Scale9Sprite = _ccsg.Node.extend({ // this._renderCmd._needDraw = false; // } // else { - this._renderCmd._needDraw = true; + // this._renderCmd._needDraw = true; // } } else { diff --git a/jsb/jsb-etc.js b/jsb/jsb-etc.js index 52fd8a009d..c15e28dfb8 100644 --- a/jsb/jsb-etc.js +++ b/jsb/jsb-etc.js @@ -197,7 +197,8 @@ window._ccsg = { TMXObjectImage: cc.TMXObjetImage, TMXObjectShape: cc.TMXObjectShape, TMXLayer: cc.TMXLayer, - MotionStreak: cc.MotionStreak + MotionStreak: cc.MotionStreak, + CameraNode: cc.CameraNode }; // __errorHandler From e1090e85e171ebb51130c3c2412b8ba5103b9c21 Mon Sep 17 00:00:00 2001 From: 2youyouo2 <501251991@qq.com> Date: Mon, 27 Mar 2017 11:28:33 +0800 Subject: [PATCH 3/6] refine camera --- cocos2d/core/camera/CCCamera.js | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/cocos2d/core/camera/CCCamera.js b/cocos2d/core/camera/CCCamera.js index 388126a54c..fa4a6f1dc8 100644 --- a/cocos2d/core/camera/CCCamera.js +++ b/cocos2d/core/camera/CCCamera.js @@ -27,9 +27,6 @@ if (!CC_JSB) { require('./CCSGCameraNode'); } -let ONE_DEGREE = Math.PI / 180; - -let cameraExists = false; let tempTransform = cc.affineTransformMake(); let Camera = cc.Class({ @@ -75,12 +72,12 @@ let Camera = cc.Class({ }, onEnable: function () { - if (cameraExists) { + if (Camera.main) { cc.warnID('8300'); return; } - cameraExists = true; + Camera.main = this; let targets = this._targets; for (let i = 0, l = targets.length; i < l; i++) { @@ -89,7 +86,7 @@ let Camera = cc.Class({ }, onDisable: function () { - cameraExists = false; + Camera.main = null; let targets = this._targets; for (let i = 0, l = targets.length; i < l; i++) { @@ -122,22 +119,13 @@ let Camera = cc.Class({ calculateCaemraTransformIn: function (transform) { let node = this.node; - // calculate world position - let pos = node.convertToWorldSpaceAR(cc.Vec2.ZERO); - - // calculate world rotation - let rotation = node.rotation; - let parent = node.parent; - while (parent){ - rotation += parent.rotation; - parent = parent.parent; - } + let wt = node.getNodeToWorldTransform(); + let rotation = -(Math.atan2(wt.b, wt.a) + Math.atan2(-wt.c, wt.d)) * 0.5; let a = 1, b = 0, c = 0, d = 1; // rotation if (rotation) { - rotation = rotation * ONE_DEGREE; c = Math.sin(rotation); d = Math.cos(rotation); a = d; @@ -153,8 +141,8 @@ let Camera = cc.Class({ // move camera to center let center = cc.visibleRect.center; - transform.tx = center.x - (a * pos.x + c * pos.y); - transform.ty = center.y - (b * pos.x + d * pos.y); + transform.tx = center.x - (a * wt.tx + c * wt.ty); + transform.ty = center.y - (b * wt.tx + d * wt.ty); transform.a = a; transform.b = b; @@ -169,4 +157,6 @@ let Camera = cc.Class({ } }); +Camera.main = null; + module.exports = cc.Camera = Camera; From 5e94bc4a87f6191bae7f7fb8cf73891c56dcb171 Mon Sep 17 00:00:00 2001 From: 2youyouo2 <501251991@qq.com> Date: Mon, 27 Mar 2017 12:00:50 +0800 Subject: [PATCH 4/6] refine camera --- DebugInfos.js | 2 +- cocos2d/core/camera/CCCamera.js | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/DebugInfos.js b/DebugInfos.js index 941771490e..a85a68d007 100644 --- a/DebugInfos.js +++ b/DebugInfos.js @@ -580,7 +580,7 @@ if (CC_DEV) { //Physics: 8200 "8200": "Please set node\'s active instead of rigidbody\'s enabled.", //cc.RigidBody.enabled //Camera: 8300 - "8300": "Should only one camera be enabled, please check your project.", //cc.Camera.enabled + "8300": "Should only one camera exists, please check your project.", //cc.Camera.enabled }; cc._LogInfos = logs; } diff --git a/cocos2d/core/camera/CCCamera.js b/cocos2d/core/camera/CCCamera.js index fa4a6f1dc8..99aa572702 100644 --- a/cocos2d/core/camera/CCCamera.js +++ b/cocos2d/core/camera/CCCamera.js @@ -73,7 +73,7 @@ let Camera = cc.Class({ onEnable: function () { if (Camera.main) { - cc.warnID('8300'); + cc.errorID(8300); return; } @@ -86,6 +86,10 @@ let Camera = cc.Class({ }, onDisable: function () { + if (Camera.main !== this) { + return; + } + Camera.main = null; let targets = this._targets; From 6c77064f2c57d0f54a1538bdff8a94de4d201337 Mon Sep 17 00:00:00 2001 From: 2youyouo2 <501251991@qq.com> Date: Mon, 27 Mar 2017 14:41:06 +0800 Subject: [PATCH 5/6] set camera executeInEditMode to false --- cocos2d/core/camera/CCCamera.js | 1 + 1 file changed, 1 insertion(+) diff --git a/cocos2d/core/camera/CCCamera.js b/cocos2d/core/camera/CCCamera.js index 99aa572702..baab85ea38 100644 --- a/cocos2d/core/camera/CCCamera.js +++ b/cocos2d/core/camera/CCCamera.js @@ -35,6 +35,7 @@ let Camera = cc.Class({ editor: CC_EDITOR && { menu: 'i18n:MAIN_MENU.component.others/Camera', + executeInEditMode: false }, properties: { From f55932382660524c7a921b90efc0f9f137e6246e Mon Sep 17 00:00:00 2001 From: 2youyouo2 <501251991@qq.com> Date: Mon, 27 Mar 2017 15:28:23 +0800 Subject: [PATCH 6/6] fixed matrix stack update state --- cocos2d/kazmath/gl/mat4stack.js | 6 ++++++ cocos2d/kazmath/gl/matrix.js | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cocos2d/kazmath/gl/mat4stack.js b/cocos2d/kazmath/gl/mat4stack.js index 8e2089e0bb..58059665c9 100644 --- a/cocos2d/kazmath/gl/mat4stack.js +++ b/cocos2d/kazmath/gl/mat4stack.js @@ -50,11 +50,17 @@ proto.push = function(item) { this.stack.push(this.top); this.top = new cc.math.Matrix4(item); //this.top = this._getFromPool(item); + this.update(); }; proto.pop = function() { //this._putInPool(this.top); this.top = this.stack.pop(); + this.update(); +}; + +proto.update = function () { + this.lastUpdated ++; }; proto.release = function(){ diff --git a/cocos2d/kazmath/gl/matrix.js b/cocos2d/kazmath/gl/matrix.js index db7e2fc653..3aa868815d 100644 --- a/cocos2d/kazmath/gl/matrix.js +++ b/cocos2d/kazmath/gl/matrix.js @@ -106,7 +106,6 @@ math.glMatrixMode = function (mode) { throw new Error("Invalid matrix mode specified"); //TODO: Proper error handling break; } - cc.current_stack.lastUpdated = cc.director.getTotalFrames(); }; math.glLoadIdentity = function () {