Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't change z value when invoke setPosition or setScale with two parameter #7104

Merged
merged 12 commits into from
Aug 11, 2020
26 changes: 17 additions & 9 deletions cocos2d/core/CCNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -2690,8 +2690,8 @@ let NodeDefines = {
* !#zh
* 设置节点在父节点坐标系中的位置。<br/>
* 可以通过下面的方式设置坐标点:<br/>
* 1. 传入 2 个数值 x, y。<br/>
* 2. 传入 cc.v2(x, y) 类型为 cc.Vec2 的对象。
* 1. 传入 2 个数值 x, y (此时不会改变position的z值)。<br/>
* 2. 传入 cc.v2(x, y) 类型为 cc.Vec2 的对象 (此时不会改变position的z值)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

此时 z 会被重置为 0,麻烦更正一下注释。另外中文和英文之间插入个空格

* 3. 对于 3D 节点可以传入 3 个数值 x, y, z。<br/>
* 4. 对于 3D 节点可以传入 cc.v3(x, y, z) 类型为 cc.Vec3 的对象。
* @method setPosition
Expand All @@ -2704,14 +2704,18 @@ let NodeDefines = {
if (y === undefined) {
x = newPosOrX.x;
y = newPosOrX.y;
z = newPosOrX.z || 0;
z = newPosOrX.z;
jareguo marked this conversation as resolved.
Show resolved Hide resolved
}
else {
x = newPosOrX;
z = z || 0
}

let trs = this._trs;

if (z === undefined) {
z = trs[2];
}
jareguo marked this conversation as resolved.
Show resolved Hide resolved

if (trs[0] === x && trs[1] === y && trs[2] === z) {
return;
}
Expand Down Expand Up @@ -2765,6 +2769,7 @@ let NodeDefines = {
* !#zh
* 设置节点在本地坐标系中坐标轴上的缩放比例。
* 2D 节点可以操作两个坐标轴,而 3D 节点可以操作三个坐标轴。
* 当只传入 (x, y) 或 Vec2对象时, 不会改变 scale.z 的值.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里注释也应该调整,vec2 会改变 scale z

* @method setScale
* @param {Number|Vec2|Vec3} x - scaleX or scale object
* @param {Number} [y]
Expand All @@ -2776,18 +2781,21 @@ let NodeDefines = {
*/
setScale (x, y, z) {
if (x && typeof x !== 'number') {
y = x.y;
z = x.z === undefined ? 1 : x.z;
x = x.x;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里代码执行顺序不可更改,改完之后 x 变成了 number,再获取 x.y 就报错了

y = x.y;
z = x.z;
}
else if (x !== undefined && y === undefined) {
y = x;
z = x;
}
else if (z === undefined) {
z = 1;
}

let trs = this._trs;

if (z === undefined) {
z = trs[9];
}

if (trs[7] !== x || trs[8] !== y || trs[9] !== z) {
trs[7] = x;
trs[8] = y;
Expand Down