From 918001e43f1529d898eb5964c3c33784cd57f400 Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Thu, 23 Nov 2017 11:05:12 +0800 Subject: [PATCH] make node affine transform operation compatibility --- cocos2d/core/CCNode.js | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/cocos2d/core/CCNode.js b/cocos2d/core/CCNode.js index 2712af020f..e022072201 100644 --- a/cocos2d/core/CCNode.js +++ b/cocos2d/core/CCNode.js @@ -50,6 +50,7 @@ var Event = require('./event/event'); var ActionManagerExist = !!cc.ActionManager; var emptyFunc = function () {}; var _mat4_temp = math.mat4.create(); +var _vec3_temp = math.vec3.create(); var _trans = affineTrans.make(); var _globalOrderOfArrival = 1; @@ -1873,7 +1874,14 @@ var Node = cc.Class({ out = affineTrans.makeIdentity(); } this._updateLocalMatrix(); - return affineTrans.fromMatrix(this._matrix, out); + + var contentSize = this._contentSize; + _vec3_temp.x = -this._anchorPoint.x * contentSize.width; + _vec3_temp.y = -this._anchorPoint.y * contentSize.height; + + math.mat4.copy(_mat4_temp, this._matrix); + math.mat4.translate(_mat4_temp, _mat4_temp, _vec3_temp); + return affineTrans.fromMatrix(_mat4_temp, out); }, /** @@ -1897,15 +1905,7 @@ var Node = cc.Class({ out = affineTrans.makeIdentity(); } this._updateLocalMatrix(); - - var contentSize = this._contentSize; - // see getNodeToWorldTransform - var tx = this._anchorPoint.x * contentSize.x; - var ty = this._anchorPoint.y * contentSize.y; - - math.mat4.copy(_mat4_temp, this._matrix); - math.mat4.translate(_mat4_temp, tx, ty); - return affineTrans.fromMatrix(_mat4_temp, out); + return affineTrans.fromMatrix(this._matrix, out); }, /** @@ -1923,7 +1923,15 @@ var Node = cc.Class({ out = affineTrans.makeIdentity(); } this._updateWorldMatrix(); - return affineTrans.fromMatrix(this._worldMatrix, out); + + var contentSize = this._contentSize; + _vec3_temp.x = -this._anchorPoint.x * contentSize.width; + _vec3_temp.y = -this._anchorPoint.y * contentSize.height; + + math.mat4.copy(_mat4_temp, this._worldMatrix); + math.mat4.translate(_mat4_temp, _mat4_temp, _vec2_temp); + + return affineTrans.fromMatrix(_mat4_temp, out); }, /** @@ -1945,15 +1953,7 @@ var Node = cc.Class({ out = affineTrans.makeIdentity(); } this._updateWorldMatrix(); - - var contentSize = this._contentSize; - // see getNodeToWorldTransform - var tx = this._anchorPoint.x * contentSize.width; - var ty = this._anchorPoint.y * contentSize.height; - - math.mat4.copy(_mat4_temp, this._worldMatrix); - math.mat4.translate(_mat4_temp, tx, ty); - return affineTrans.fromMatrix(_mat4_temp, out); + return affineTrans.fromMatrix(this._matrix, out); }, /**