diff --git a/cocos2d/core/CCNode.js b/cocos2d/core/CCNode.js index 60990899af..f6bc3b7cbd 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; @@ -1875,7 +1876,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); }, /** @@ -1899,15 +1907,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); }, /** @@ -1925,7 +1925,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); }, /** @@ -1947,15 +1955,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); }, /** diff --git a/cocos2d/core/value-types/index.js b/cocos2d/core/value-types/index.js index b73a6b94e4..df2f0670de 100644 --- a/cocos2d/core/value-types/index.js +++ b/cocos2d/core/value-types/index.js @@ -32,4 +32,6 @@ require('./CCRect'); require('./CCColor'); require('./CCTypes'); require('./CCAffineTransform'); -require('./CCTypesWebGL'); \ No newline at end of file +require('./CCTypesWebGL'); + +cc.vmath = require('../renderer/render-engine').math; diff --git a/cocos2d/deprecated.js b/cocos2d/deprecated.js index 79449e24cc..facfcf5198 100644 --- a/cocos2d/deprecated.js +++ b/cocos2d/deprecated.js @@ -317,6 +317,25 @@ if (CC_DEV) { } } + function markFunctionWarning (ownerCtor, obj, ownerName) { + if (!ownerCtor) { + // 可能被裁剪了 + return; + } + ownerName = ownerName || js.getClassName(ownerCtor); + for (var prop in obj) { + var originFunc = ownerCtor[prop]; + if (!originFunc) return; + + function warn () { + cc.warn('Sorry, %s.%s is deprecated. Please use %s instead', ownerName, prop, obj[prop]); + return originFunc.apply(this, arguments); + } + + ownerCtor[prop] = warn; + } + } + // cc.director provideClearError(cc.Director.prototype, { @@ -409,8 +428,18 @@ if (CC_DEV) { 'setCascadeColorEnabled', 'ignoreAnchor', 'isIgnoreAnchorPointForPosition', - 'ignoreAnchorPointForPosition' + 'ignoreAnchorPointForPosition', ]); + + markFunctionWarning(cc.Node.prototype, { + 'getNodeToParentTransform': 'getLocalMatrix', + 'getNodeToParentTransformAR': 'getLocalMatrix', + 'getNodeToWorldTransform': 'getWorldMatrix', + 'getNodeToWorldTransformAR': 'getWorldMatrix', + 'getParentToNodeTransform': 'getLocalMatrix', + 'getWorldToNodeTransform': 'getWorldMatrix', + }); + provideClearError(cc.Node.prototype, { arrivalOrder: 'getSiblingIndex, setSiblingIndex', _visible: '_activeInHierarchy, active', @@ -431,7 +460,7 @@ if (CC_DEV) { worldToNodeTransform: 'getWorldToNodeTransform', nodeToParentTransform: 'getNodeToParentTransform', removeAllComponents: 'removeComponent', - getNodeToParentAffineTransform: 'getNodeToParentTransform', + getNodeToParentAffineTransform: 'getNodeToParentTransform' });