From 22a1e2994a7650b5a42572700f3a42aa68e7648d Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Fri, 9 Mar 2018 16:12:00 +0800 Subject: [PATCH 1/7] 1. support camera sort 2. support camera culling mask with node group 3. add MAIN_CAMERA to Canvas --- cocos2d/core/CCDirector.js | 11 +- cocos2d/core/CCNode.js | 5 +- cocos2d/core/camera/CCCamera.js | 240 +++++++++++------- cocos2d/core/components/CCCanvas.js | 16 ++ cocos2d/core/renderer/index.js | 47 ++-- .../core/renderer/render-component-walker.js | 17 +- cocos2d/core/renderer/render-engine.js | 6 + cocos2d/deprecated.js | 6 + 8 files changed, 222 insertions(+), 126 deletions(-) diff --git a/cocos2d/core/CCDirector.js b/cocos2d/core/CCDirector.js index 170a16cdec..a999e9696e 100644 --- a/cocos2d/core/CCDirector.js +++ b/cocos2d/core/CCDirector.js @@ -790,12 +790,11 @@ cc.Director.prototype = { * @deprecated */ setClearColor: function (clearColor) { - renderer._camera.setColor( - clearColor.r / 255, - clearColor.g / 255, - clearColor.b / 255, - clearColor.a / 255 - ); + if (!cc.Camera.main) { + return; + } + + cc.Camera.main.backgroundColor = clearColor; }, /** diff --git a/cocos2d/core/CCNode.js b/cocos2d/core/CCNode.js index 031ae16fee..0351f82b97 100644 --- a/cocos2d/core/CCNode.js +++ b/cocos2d/core/CCNode.js @@ -38,6 +38,7 @@ const POSITION_CHANGED = 'position-changed'; const SIZE_CHANGED = 'size-changed'; const ANCHOR_CHANGED = 'anchor-changed'; const ROTATION_CHANGED = 'rotation-changed'; +const WORLD_MATRIX_CHANGED = 'world-matrix-changed'; const SCALE_CHANGED = 'scale-changed'; const CHILD_REORDER = 'child-reorder'; @@ -941,8 +942,7 @@ var Node = cc.Class({ this._localMatDirty = true; this._worldMatDirty = true; - this._cullingMask = 1; - this._inheritMask = 1; + this._cullingMask = 1 << this.group; }, statics: { @@ -1973,6 +1973,7 @@ var Node = cc.Class({ else { math.mat4.copy(this._worldMatrix, this._matrix); } + this.emit(WORLD_MATRIX_CHANGED); this._worldMatDirty = false; for (let i = 0, len = this._children.length; i < len; ++i) { diff --git a/cocos2d/core/camera/CCCamera.js b/cocos2d/core/camera/CCCamera.js index 7d63a5961b..bccba8ef51 100644 --- a/cocos2d/core/camera/CCCamera.js +++ b/cocos2d/core/camera/CCCamera.js @@ -31,8 +31,6 @@ const mat4 = cc.vmath.mat4; const vec2 = cc.vmath.vec2; const vec3 = cc.vmath.vec3; -let _static_culling_mask = 1; - let _mat4_temp_1 = mat4.create(); let _mat4_temp_2 = mat4.create(); let _vec3_temp_1 = vec3.create(); @@ -40,6 +38,17 @@ let _vec3_temp_2 = vec3.create(); let _cameras = []; +/** + * !#en Values for Camera.clearFlags, determining what to clear when rendering a Camera. + * !#zh 摄像机清除标记位,决定摄像机渲染时会清除哪些状态 + * @enum Camera.ClearFlags + */ +let ClearFlags = cc.Enum({ + COLOR: 1, + DEPTH: 2, + STENCIL: 4, +}); + /** * !#en * Camera is usefull when making reel game or other games which need scroll screen. @@ -61,8 +70,6 @@ let Camera = cc.Class({ 'transparent' ]); - camera.setClearFlags(0); - this._fov = Math.PI * 60 / 180; camera.setFov(this._fov); camera.setNear(0.1); @@ -72,23 +79,23 @@ let Camera = cc.Class({ camera.view = view; camera.dirty = true; - this.cullingMask = 1 << _static_culling_mask++; - camera._cullingMask = view._cullingMask = this.cullingMask; + this._matrixDirty = true; this._camera = camera; }, editor: CC_EDITOR && { menu: 'i18n:MAIN_MENU.component.others/Camera', + inspector: 'packages://inspector/inspectors/comps/camera.js', executeInEditMode: false }, properties: { - _targets: { - default: [], - type: cc.Node, - visible: true - }, + _cullingMask: 0xffffffff, + _clearFlags: 0, + _backgroundColor: cc.color(51, 77, 120, 255), + _depth: 0, + _zoomRatio: 1, /** * !#en @@ -97,22 +104,116 @@ let Camera = cc.Class({ * 摄像机缩放比率 * @property {Number} zoomRatio */ - zoomRatio: 1, + zoomRatio: { + get () { + return this._zoomRatio; + }, + set (value) { + this._zoomRatio = value; + this._matrixDirty = true; + } + }, + + /** + * !#en + * This is used to render parts of the scene selectively. + * !#zh + * 决定摄像机会渲染场景的哪一部分。 + * @property {Number} cullingMask + */ + cullingMask: { + get () { + return this._cullingMask; + }, + set (value) { + this._cullingMask = value; + this._updateCameraMask(); + } + }, + + /** + * !#en + * Determining what to clear when camera rendering. + * !#zh + * 决定摄像机渲染时会清除哪些状态。 + * @property {Number} clearFlags + */ + clearFlags: { + get () { + return this._clearFlags; + }, + set (value) { + this._clearFlags = value; + this._camera.setClearFlags(value); + } + }, + + /** + * !#en + * The color with which the screen will be cleared. + * !#zh + * 摄像机用于清除屏幕的背景色。 + */ + backgroundColor: { + get () { + return this._backgroundColor; + }, + set (value) { + this._backgroundColor = value; + this._updateBackgroundColor(); + } + }, + + /** + * !#en + * Camera's depth in the camera rendering order. + * !#zh + * 摄像机深度,用于决定摄像机的渲染顺序。 + */ + depth: { + get () { + return this._depth; + }, + set (value) { + this._depth = value; + this._camera.setDepth(value); + } + } }, statics: { /** * !#en - * Current active camera, the scene should only have one active camera at the same time. + * The first enabled camera. * !#zh - * 当前激活的摄像机,场景中在同一时间内只能有一个激活的摄像机。 + * 第一个被激活的摄像机。 * @property {Camera} main * @static */ main: null, + /** + * !#en + * All enabled cameras. + * !#zh + * 激活的所有摄像机。 + * @property {[Camera]} cameras + * @static + */ cameras: _cameras, + ClearFlags: ClearFlags, + + /** + * !#en + * Get the first camera which the node belong to. + * !#zh + * 获取节点所在的第一个摄像机。 + * @method findCamera + * @param {Node} node + * @return {Camera} + * @static + */ findCamera (node) { for (let i = 0, l = _cameras.length; i < l; i++) { let camera = _cameras[i]; @@ -125,88 +226,48 @@ let Camera = cc.Class({ } }, + _updateCameraMask () { + this._camera._cullingMask = this._cullingMask; + this._camera.view._cullingMask = this._cullingMask; + }, + + _updateBackgroundColor () { + let color = this._backgroundColor; + this._camera.setColor( + color.r / 255, + color.g / 255, + color.b / 255, + color.a / 255, + ); + }, + + _onMatrixDirty () { + this._matrixDirty = true; + }, + onLoad () { this._camera.setNode(this.node); + this._camera.setClearFlags(this._clearFlags); + this._camera.setDepth(this._depth); + this._updateBackgroundColor(); + this._updateCameraMask(); }, onEnable () { - if (CC_EDITOR) return; - - if (!Camera.main) { - Camera.main = this; - } - - let targets = this._targets; - for (let i = 0, l = targets.length; i < l; i++) { - targets[i]._cullingMask = this.cullingMask; - } + this.node.on('world-matrix-changed', this._onMatrixDirty, this); + this._matrixDirty = true; renderer.scene.addCamera(this._camera); _cameras.push(this); }, onDisable () { - if (CC_EDITOR) return; - - if (Camera.main === this) { - Camera.main = null; - } - - let targets = this._targets; - for (let i = 0, l = targets.length; i < l; i++) { - targets[i]._cullingMask = 1; - } + this.node.off('world-matrix-changed', this._onMatrixDirty, this); renderer.scene.removeCamera(this._camera); cc.js.array.remove(_cameras, this); }, - /** - * !#en - * Add the specified target to camera. - * !#zh - * 将指定的节点添加到摄像机中。 - * @method addTarget - * @param {Node} target - */ - addTarget (target) { - if (this._targets.indexOf(target) !== -1) { - return; - } - - target._cullingMask = this.cullingMask; - this._targets.push(target); - }, - - /** - * !#en - * Remove the specified target from camera. - * !#zh - * 将指定的节点从摄像机中移除。 - * @method removeTarget - * @param {Node} target - */ - removeTarget (target) { - if (this._targets.indexOf(target) === -1) { - return; - } - - target._cullingMask = 1; - cc.js.array.remove(this._targets, target); - }, - - /** - * !#en - * Get all camera targets. - * !#zh - * 获取所有摄像机目标节点。 - * @method getTargets - * @return {[Node]} - */ - getTargets () { - return this._targets; - }, - /** * !#en * Returns the matrix that transform the node's (local) space coordinates into the camera's space coordinates. @@ -315,25 +376,28 @@ let Camera = cc.Class({ * @return {Boolean} */ containsNode (node) { - return node._inheritMask === this.cullingMask; + return node._cullingMask === this.cullingMask; }, lateUpdate: !CC_EDITOR && function () { let node = this.node; - - let zoomRatio = this.zoomRatio; - let min = -(zoomRatio/2-0.5); - this._camera.setRect(min,min,zoomRatio,zoomRatio); - - node.z = renderer.canvas.height / cc.view.getScaleY() / 1.1566; node.getWorldMatrix(_mat4_temp_1); + + if (!this._matrixDirty) return; + + let camera = this._camera; + let fov = Math.atan(Math.tan(this._fov/2) / this.zoomRatio)*2; + camera.setFov(fov); _vec3_temp_1.x = _mat4_temp_1.m12; _vec3_temp_1.y = _mat4_temp_1.m13; _vec3_temp_1.z = 0; + + node.z = cc.visibleRect.height / 1.1566; node.lookAt(_vec3_temp_1); - this._camera.dirty = true; + this._matrixDirty = false; + camera.dirty = true; } }); diff --git a/cocos2d/core/components/CCCanvas.js b/cocos2d/core/components/CCCanvas.js index f2968b2760..d58111b2ce 100644 --- a/cocos2d/core/components/CCCanvas.js +++ b/cocos2d/core/components/CCCanvas.js @@ -162,6 +162,22 @@ var Canvas = cc.Class({ this.applySettings(); this.onResized(); + + let cameraNode = cc.find('MAIN_CAMERA', this.node); + if (!cameraNode) { + cameraNode = new cc.Node('MAIN_CAMERA'); + cameraNode.parent = this.node; + cameraNode.setSiblingIndex(0); + } + let camera = cameraNode.getComponent(cc.Camera); + if (!camera) { + camera = cameraNode.addComponent(cc.Camera); + + let ClearFlags = cc.Camera.ClearFlags; + camera.clearFlags = ClearFlags.COLOR | ClearFlags.DEPTH; + camera.depth = -1; + } + cc.Camera.main = camera; }, onDestroy: function () { diff --git a/cocos2d/core/renderer/index.js b/cocos2d/core/renderer/index.js index 40fec2c42c..0e86672d49 100644 --- a/cocos2d/core/renderer/index.js +++ b/cocos2d/core/renderer/index.js @@ -83,26 +83,28 @@ module.exports = { this._walker = new RenderComponentWalker(this.device, this.scene); - this._cameraNode = new cc.Node(); - - this._camera = new renderEngine.Camera(); - this._camera.setColor(0, 0, 0, 1); - this._camera.setFov(Math.PI * 60 / 180); - this._camera.setNear(0.1); - this._camera.setFar(1024); - this._camera.setNode(this._cameraNode); - - let view = new renderEngine.View(); - this._camera.view = view; - this._camera.dirty = true; - if (CC_EDITOR) { - this._camera.setColor(0, 0, 0, 0); + this._cameraNode = new cc.Node(); + + this._camera = new renderEngine.Camera(); + this._camera.setColor(0, 0, 0, 1); + this._camera.setFov(Math.PI * 60 / 180); + this._camera.setNear(0.1); + this._camera.setFar(1024); + this._camera.setNode(this._cameraNode); + + let view = new renderEngine.View(); + this._camera.view = view; + this._camera.dirty = true; + + if (CC_EDITOR) { + this._camera.setColor(0, 0, 0, 0); + } + this._camera.setStages([ + 'transparent' + ]); + this.scene.addCamera(this._camera); } - this._camera.setStages([ - 'transparent' - ]); - this.scene.addCamera(this._camera); let builtins = _initBuiltins(this.device); this._forward = new renderEngine.ForwardRenderer(this.device, builtins); @@ -135,16 +137,17 @@ module.exports = { this._camera.tx = vp.x; this._camera.ty = vp.y + vp.height; } - else if (this.canvas) { - let node = this._cameraNode; + else if (CC_EDITOR && this.canvas) { let canvas = this.canvas; let scaleX = cc.view.getScaleX(); let scaleY = cc.view.getScaleY(); - let zeye = canvas.height / scaleY / 1.1566; + + let node = this._cameraNode; _pos.x = node.x = canvas.width / scaleX / 2; _pos.y = node.y = canvas.height / scaleY / 2; - node.z = zeye; _pos.z = 0; + + node.z = this.canvas.height / cc.view.getScaleY() / 1.1566; node.lookAt(_pos); this._camera.dirty = true; } diff --git a/cocos2d/core/renderer/render-component-walker.js b/cocos2d/core/renderer/render-component-walker.js index 1bbbea3f94..f4d218cdb4 100644 --- a/cocos2d/core/renderer/render-component-walker.js +++ b/cocos2d/core/renderer/render-component-walker.js @@ -98,6 +98,11 @@ var RenderComponentWalker = function (device, renderScene) { this._dummyNode = new cc.Node(); this._node = this._dummyNode; this._sortKey = 0; + + this._curCameraNode = null; + + this._handleRender = this._handleRender.bind(this); + this._postHandleRender = this._postHandleRender.bind(this); }; RenderComponentWalker.prototype = { @@ -136,16 +141,12 @@ RenderComponentWalker.prototype = { }, _handleRender (node) { - if (node._cullingMask !== 1) { + if (node.groupIndex !== 0) { this._curCameraNode = node; } - if (this._curCameraNode) { - node._inheritMask = this._curCameraNode._cullingMask; - } - else { - node._inheritMask = 1; - } + let group = this._curCameraNode ? this._curCameraNode.groupIndex : node.groupIndex; + node._cullingMask = 1 << group; let comp = node._renderComponent; if (comp) { @@ -284,7 +285,7 @@ RenderComponentWalker.prototype = { else { this._node = this._dummyNode; } - cullingMask = comp.node._inheritMask; + cullingMask = comp.node._cullingMask; for (let id = 0; id < datas.length; id ++) { data = datas[id]; diff --git a/cocos2d/core/renderer/render-engine.js b/cocos2d/core/renderer/render-engine.js index 9de212b41c..62b195616a 100644 --- a/cocos2d/core/renderer/render-engine.js +++ b/cocos2d/core/renderer/render-engine.js @@ -13560,6 +13560,12 @@ module.exports = (function () { this._reset(); const canvas = this._device._gl.canvas; + + scene._cameras.sort((a, b) => { + if (a._depth > b._depth) return 1; + else if (a._depth < b._depth) return -1; + else return 0; + }); for (let i = 0; i < scene._cameras.length; ++i) { let camera = scene._cameras.data[i]; diff --git a/cocos2d/deprecated.js b/cocos2d/deprecated.js index ad702bdb1c..16a459bdd0 100644 --- a/cocos2d/deprecated.js +++ b/cocos2d/deprecated.js @@ -457,6 +457,12 @@ if (CC_DEV) { 'ignoreAnchorPointForPosition', ]); + markAsRemoved(cc.Camera, [ + 'addTarget', + 'removeTarget', + 'getTargets' + ]); + markFunctionWarning(cc.Node.prototype, { 'getNodeToParentTransform': 'getLocalMatrix', 'getNodeToParentTransformAR': 'getLocalMatrix', From f441dba72220d0c1cfffb123d4d880551cce5d26 Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Fri, 9 Mar 2018 16:36:11 +0800 Subject: [PATCH 2/7] remove attachDebugDrawToCamera & detachDebugDrawFromCamera --- cocos2d/core/collider/CCCollisionManager.js | 9 ------- cocos2d/core/physics/CCPhysicsManager.js | 27 --------------------- cocos2d/deprecated.js | 10 ++++++++ 3 files changed, 10 insertions(+), 36 deletions(-) diff --git a/cocos2d/core/collider/CCCollisionManager.js b/cocos2d/core/collider/CCCollisionManager.js index e6f0605a45..da70194036 100644 --- a/cocos2d/core/collider/CCCollisionManager.js +++ b/cocos2d/core/collider/CCCollisionManager.js @@ -339,15 +339,6 @@ let 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) { let node = event.currentTarget; let colliders = node.getComponents(cc.Collider); diff --git a/cocos2d/core/physics/CCPhysicsManager.js b/cocos2d/core/physics/CCPhysicsManager.js index e9660c2959..09bb9629d2 100644 --- a/cocos2d/core/physics/CCPhysicsManager.js +++ b/cocos2d/core/physics/CCPhysicsManager.js @@ -347,33 +347,6 @@ var PhysicsManager = cc.Class({ } }, - /** - * !#en - * Attach physics debug draw to camera - * !#zh - * 将物理的调试绘制信息附加到指定摄像机上 - * @method attachDebugDrawToCamera - * @param {Camera} camera - */ - attachDebugDrawToCamera: function (camera) { - if (!this.debugDrawFlags) return; - this._checkDebugDrawValid(); - camera.addTarget(this._debugDrawer.node); - }, - /** - * !#en - * Detach physics debug draw to camera - * !#zh - * 将物理的调试绘制信息从指定摄像机上移除 - * @method detachDebugDrawFromCamera - * @param {Camera} camera - */ - detachDebugDrawFromCamera: function (camera) { - if (!this.debugDrawFlags) return; - this._checkDebugDrawValid(); - camera.removeTarget(this._debugDrawer.node); - }, - _registerContactFixture: function (fixture) { this._contactListener.registerContactFixture(fixture); }, diff --git a/cocos2d/deprecated.js b/cocos2d/deprecated.js index 16a459bdd0..5458ea93d3 100644 --- a/cocos2d/deprecated.js +++ b/cocos2d/deprecated.js @@ -463,6 +463,16 @@ if (CC_DEV) { 'getTargets' ]); + markAsRemoved(cc.PhysicsManager, [ + 'attachDebugDrawToCamera', + 'detachDebugDrawFromCamera', + ]); + + markAsRemoved(cc.CollisionManager, [ + 'attachDebugDrawToCamera', + 'detachDebugDrawFromCamera', + ]); + markFunctionWarning(cc.Node.prototype, { 'getNodeToParentTransform': 'getLocalMatrix', 'getNodeToParentTransformAR': 'getLocalMatrix', From efb8e24f23454f85fb713c96d9fa58e32d44b231 Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Fri, 9 Mar 2018 18:19:38 +0800 Subject: [PATCH 3/7] revert code --- cocos2d/core/renderer/render-component-walker.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/cocos2d/core/renderer/render-component-walker.js b/cocos2d/core/renderer/render-component-walker.js index 4b7c0c0479..9dbbc5bdd8 100644 --- a/cocos2d/core/renderer/render-component-walker.js +++ b/cocos2d/core/renderer/render-component-walker.js @@ -277,14 +277,6 @@ RenderComponentWalker.prototype = { // Update render data datas = assembler.updateRenderData(comp, _batchData); - // Set model - if (assembler.useModel) { - this._node = comp.node; - } - else { - this._node = this._dummyNode; - } - cullingMask = comp.node._cullingMask; for (let id = 0; id < datas.length; id ++) { From de77c38b2b00d3b6ac5781f6f50c707e536fa8c0 Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Mon, 12 Mar 2018 10:33:14 +0800 Subject: [PATCH 4/7] change 'MAIN_CAMERA' to 'Main Camera' --- cocos2d/core/components/CCCanvas.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos2d/core/components/CCCanvas.js b/cocos2d/core/components/CCCanvas.js index d58111b2ce..3744552af9 100644 --- a/cocos2d/core/components/CCCanvas.js +++ b/cocos2d/core/components/CCCanvas.js @@ -163,9 +163,9 @@ var Canvas = cc.Class({ this.applySettings(); this.onResized(); - let cameraNode = cc.find('MAIN_CAMERA', this.node); + let cameraNode = cc.find('Main Camera', this.node); if (!cameraNode) { - cameraNode = new cc.Node('MAIN_CAMERA'); + cameraNode = new cc.Node('Main Camera'); cameraNode.parent = this.node; cameraNode.setSiblingIndex(0); } From 1d8ec5affa10f0016a39d49ca5f8499e9c70fae0 Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Mon, 12 Mar 2018 14:27:36 +0800 Subject: [PATCH 5/7] refine code --- cocos2d/core/renderer/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/core/renderer/index.js b/cocos2d/core/renderer/index.js index 0e86672d49..f739aef2d5 100644 --- a/cocos2d/core/renderer/index.js +++ b/cocos2d/core/renderer/index.js @@ -147,7 +147,7 @@ module.exports = { _pos.y = node.y = canvas.height / scaleY / 2; _pos.z = 0; - node.z = this.canvas.height / cc.view.getScaleY() / 1.1566; + node.z = canvas.height / scaleY / 1.1566; node.lookAt(_pos); this._camera.dirty = true; } From 8705d6f4d590bea6e28e577e156542bb773edace Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Mon, 12 Mar 2018 15:59:49 +0800 Subject: [PATCH 6/7] fixed node cullingMask initialize --- cocos2d/core/CCNode.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/core/CCNode.js b/cocos2d/core/CCNode.js index 37138070c4..b5c31117cd 100644 --- a/cocos2d/core/CCNode.js +++ b/cocos2d/core/CCNode.js @@ -952,7 +952,7 @@ var Node = cc.Class({ this._localMatDirty = true; this._worldMatDirty = true; - this._cullingMask = 1 << this.group; + this._cullingMask = 1 << this.groupIndex; }, statics: { From 666bf0161114f8bfb1b62d7294d85a609029cbdd Mon Sep 17 00:00:00 2001 From: pandamicro Date: Mon, 12 Mar 2018 16:16:02 +0800 Subject: [PATCH 7/7] Fix Node API usage issue --- cocos2d/actions/CCActionCatmullRom.js | 10 +++---- cocos2d/actions/CCActionInterval.js | 34 ++++++++++------------ cocos2d/core/components/CCScrollBar.js | 4 +-- test/qunit/unit-es5/test-spriteRenderer.js | 14 ++++----- 4 files changed, 30 insertions(+), 32 deletions(-) diff --git a/cocos2d/actions/CCActionCatmullRom.js b/cocos2d/actions/CCActionCatmullRom.js index b88793f6c5..b7c1024de7 100644 --- a/cocos2d/actions/CCActionCatmullRom.js +++ b/cocos2d/actions/CCActionCatmullRom.js @@ -148,7 +148,7 @@ cc.CardinalSplineTo = cc.Class({ cc.ActionInterval.prototype.startWithTarget.call(this, target); // Issue #1441 from cocos2d-iphone this._deltaT = 1 / (this._points.length - 1); - this._previousPosition = cc.p(this.target.getPositionX(), this.target.getPositionY()); + this._previousPosition = cc.p(this.target.x, this.target.y); this._accumulatedDiff = cc.p(0, 0); }, @@ -178,8 +178,8 @@ cc.CardinalSplineTo = cc.Class({ if (cc.macro.ENABLE_STACKABLE_ACTIONS) { var tempX, tempY; - tempX = this.target.getPositionX() - this._previousPosition.x; - tempY = this.target.getPositionY() - this._previousPosition.y; + tempX = this.target.x - this._previousPosition.x; + tempY = this.target.y - this._previousPosition.y; if (tempX !== 0 || tempY !== 0) { var locAccDiff = this._accumulatedDiff; tempX = locAccDiff.x + tempX; @@ -270,8 +270,8 @@ cc.CardinalSplineBy = cc.Class({ startWithTarget:function (target) { cc.CardinalSplineTo.prototype.startWithTarget.call(this, target); - this._startPosition.x = target.getPositionX(); - this._startPosition.y = target.getPositionY(); + this._startPosition.x = target.x; + this._startPosition.y = target.y; }, reverse:function () { diff --git a/cocos2d/actions/CCActionInterval.js b/cocos2d/actions/CCActionInterval.js index 6031a7165a..d60900712c 100644 --- a/cocos2d/actions/CCActionInterval.js +++ b/cocos2d/actions/CCActionInterval.js @@ -1101,8 +1101,8 @@ cc.MoveBy = cc.Class({ startWithTarget:function (target) { cc.ActionInterval.prototype.startWithTarget.call(this, target); - var locPosX = target.getPositionX(); - var locPosY = target.getPositionY(); + var locPosX = target.x; + var locPosY = target.y; this._previousPosition.x = locPosX; this._previousPosition.y = locPosY; this._startPosition.x = locPosX; @@ -1116,8 +1116,8 @@ cc.MoveBy = cc.Class({ var y = this._positionDelta.y * dt; var locStartPosition = this._startPosition; if (cc.macro.ENABLE_STACKABLE_ACTIONS) { - var targetX = this.target.getPositionX(); - var targetY = this.target.getPositionY(); + var targetX = this.target.x; + var targetY = this.target.y; var locPreviousPosition = this._previousPosition; locStartPosition.x = locStartPosition.x + targetX - locPreviousPosition.x; @@ -1213,8 +1213,8 @@ cc.MoveTo = cc.Class({ startWithTarget:function (target) { cc.MoveBy.prototype.startWithTarget.call(this, target); - this._positionDelta.x = this._endPosition.x - target.getPositionX(); - this._positionDelta.y = this._endPosition.y - target.getPositionY(); + this._positionDelta.x = this._endPosition.x - target.x; + this._positionDelta.y = this._endPosition.y - target.y; } }); @@ -1471,8 +1471,8 @@ cc.JumpBy = cc.Class({ startWithTarget:function (target) { cc.ActionInterval.prototype.startWithTarget.call(this, target); - var locPosX = target.getPositionX(); - var locPosY = target.getPositionY(); + var locPosX = target.x; + var locPosY = target.y; this._previousPosition.x = locPosX; this._previousPosition.y = locPosY; this._startPosition.x = locPosX; @@ -1489,8 +1489,8 @@ cc.JumpBy = cc.Class({ var x = this._delta.x * dt; var locStartPosition = this._startPosition; if (cc.macro.ENABLE_STACKABLE_ACTIONS) { - var targetX = this.target.getPositionX(); - var targetY = this.target.getPositionY(); + var targetX = this.target.x; + var targetY = this.target.y; var locPreviousPosition = this._previousPosition; locStartPosition.x = locStartPosition.x + targetX - locPreviousPosition.x; @@ -1672,8 +1672,8 @@ cc.BezierBy = cc.Class({ startWithTarget:function (target) { cc.ActionInterval.prototype.startWithTarget.call(this, target); - var locPosX = target.getPositionX(); - var locPosY = target.getPositionY(); + var locPosX = target.x; + var locPosY = target.y; this._previousPosition.x = locPosX; this._previousPosition.y = locPosY; this._startPosition.x = locPosX; @@ -1699,8 +1699,8 @@ cc.BezierBy = cc.Class({ var locStartPosition = this._startPosition; if (cc.macro.ENABLE_STACKABLE_ACTIONS) { - var targetX = this.target.getPositionX(); - var targetY = this.target.getPositionY(); + var targetX = this.target.x; + var targetY = this.target.y; var locPreviousPosition = this._previousPosition; locStartPosition.x = locStartPosition.x + targetX - locPreviousPosition.x; @@ -2268,12 +2268,10 @@ cc.TintTo = cc.Class({ dt = this._computeEaseTime(dt); var locFrom = this._from, locTo = this._to; if (locFrom) { - this.target.setColor( - cc.color( + this.target.color = cc.color( locFrom.r + (locTo.r - locFrom.r) * dt, locFrom.g + (locTo.g - locFrom.g) * dt, - locFrom.b + (locTo.b - locFrom.b) * dt) - ); + locFrom.b + (locTo.b - locFrom.b) * dt); } } }); diff --git a/cocos2d/core/components/CCScrollBar.js b/cocos2d/core/components/CCScrollBar.js index 670a580782..0dfdb247de 100644 --- a/cocos2d/core/components/CCScrollBar.js +++ b/cocos2d/core/components/CCScrollBar.js @@ -138,8 +138,8 @@ var Scrollbar = cc.Class({ _setOpacity: function(opacity) { if (this.handle) { - this.node.setOpacity(opacity); - this.handle.node.setOpacity(opacity); + this.node.opacity = opacity; + this.handle.node.opacity = opacity; } }, diff --git a/test/qunit/unit-es5/test-spriteRenderer.js b/test/qunit/unit-es5/test-spriteRenderer.js index 6d57188253..15319407fd 100644 --- a/test/qunit/unit-es5/test-spriteRenderer.js +++ b/test/qunit/unit-es5/test-spriteRenderer.js @@ -40,7 +40,7 @@ test('simple spriteQuad trimmed', function () { var isTrimmed = true; var s9Sprite = new cc.Scale9Sprite(spriteFrame); s9Sprite.setContentSize(contentSize); - s9Sprite.setColor(color); + s9Sprite.color = color; s9Sprite.enableTrimmedContentSize(isTrimmed); s9Sprite.setRenderingType(cc.Scale9Sprite.RenderingType.SIMPLE); s9Sprite._rebuildQuads(); @@ -73,7 +73,7 @@ test('simple spriteQuad no trimmed', function () { var isTrimmed = false; var s9Sprite = new cc.Scale9Sprite(spriteFrame); s9Sprite.setContentSize(contentSize); - s9Sprite.setColor(color); + s9Sprite.color = color; s9Sprite.enableTrimmedContentSize(isTrimmed); s9Sprite.setRenderingType(cc.Scale9Sprite.RenderingType.SIMPLE); s9Sprite._rebuildQuads(); @@ -112,7 +112,7 @@ test('scale9 spriteQuad trimmed', function () { s9Sprite.setInsetTop(8); s9Sprite.setContentSize(contentSize); - s9Sprite.setColor(color); + s9Sprite.color = color; s9Sprite.enableTrimmedContentSize(isTrimmed); s9Sprite.setRenderingType(cc.Scale9Sprite.RenderingType.SLICED); s9Sprite._rebuildQuads(); @@ -151,7 +151,7 @@ test('tiled spriteQuad trimmed', function () { var isTrimmed = true; var s9Sprite = new cc.Scale9Sprite(spriteFrame); s9Sprite.setContentSize(contentSize); - s9Sprite.setColor(color); + s9Sprite.color = color; s9Sprite.enableTrimmedContentSize(isTrimmed); s9Sprite.setRenderingType(cc.Scale9Sprite.RenderingType.TILED); s9Sprite._rebuildQuads(); @@ -191,7 +191,7 @@ test('filled-bar-horizontal spriteQuad trimmed', function () { var isTrimmed = true; var s9Sprite = new cc.Scale9Sprite(spriteFrame); s9Sprite.setContentSize(contentSize); - s9Sprite.setColor(color); + s9Sprite.color = color; s9Sprite.enableTrimmedContentSize(isTrimmed); s9Sprite.setRenderingType(cc.Scale9Sprite.RenderingType.FILLED); s9Sprite.setFillType(cc.Scale9Sprite.FillType.HORIZONTAL); @@ -241,7 +241,7 @@ test('filled-bar-vertical spriteQuad trimmed', function () { var isTrimmed = true; var s9Sprite = new cc.Scale9Sprite(spriteFrame); s9Sprite.setContentSize(contentSize); - s9Sprite.setColor(color); + s9Sprite.color = color; s9Sprite.enableTrimmedContentSize(isTrimmed); s9Sprite.setRenderingType(cc.Scale9Sprite.RenderingType.FILLED); s9Sprite.setFillType(cc.Scale9Sprite.FillType.VERTICAL); @@ -291,7 +291,7 @@ test('filled-bar-radial spriteQuad trimmed', function () { var isTrimmed = true; var s9Sprite = new cc.Scale9Sprite(spriteFrame); s9Sprite.setContentSize(contentSize); - s9Sprite.setColor(color); + s9Sprite.color = color; s9Sprite.enableTrimmedContentSize(isTrimmed); s9Sprite.setRenderingType(cc.Scale9Sprite.RenderingType.FILLED); s9Sprite.setFillType(cc.Scale9Sprite.FillType.RADIAL);