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

Conversation

finscn
Copy link

@finscn finscn commented Aug 8, 2020

当不传入 z 时, 不会改变 node的 position.z / scale.z 值

Re: cocos-creator/2d-tasks#

Changes:
*

finscn added 2 commits Aug 8, 2020
当不传入 z 时,  不会改变 node的 position.z 值
cocos2d/core/CCNode.js Show resolved Hide resolved
cocos2d/core/CCNode.js Show resolved Hide resolved
* 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
Member

@jareguo jareguo Aug 8, 2020

Choose a reason for hiding this comment

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

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

@@ -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
Member

@jareguo jareguo Aug 8, 2020

Choose a reason for hiding this comment

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

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

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

@jareguo jareguo Aug 8, 2020

Choose a reason for hiding this comment

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

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

@finscn finscn changed the title 修改setPosition的默认行为. 修改 cc.Node 的 setPosition() 和 setScale() 的默认行为. Aug 8, 2020
x = newPosOrX;
z = z || 0
setPosition (x, y, z) {
if (x && typeof x !== 'number') {
Copy link
Member

@pandamicro pandamicro Aug 10, 2020

Choose a reason for hiding this comment

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

没必要用 typeof 判断,我们不希望过多防御,对于参数类型的区别,仅通过参数数量来识别即可

Copy link
Author

@finscn finscn Aug 10, 2020

Choose a reason for hiding this comment

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

我是看到 setScale里用了, 才改的这个地方. 那直接判断 y === undefined ? 那 setScale是不是也要改?

* @method setScale
* @param {Number|Vec2|Vec3} x - scaleX or scale object
* @param {Number} [y]
* @param {Number} [z]
* @example
* node.setScale(cc.v2(2, 2));
* node.setScale(cc.v2(2, 2)); // Notice: scaleZ will be 0
Copy link
Member

@pandamicro pandamicro Aug 10, 2020

Choose a reason for hiding this comment

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

scaleZ will remain unchanged

Copy link
Author

@finscn finscn Aug 10, 2020

Choose a reason for hiding this comment

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

按照目前的设计 cc.v2 的z=0 , 所以 会用0覆盖scaleZ.

cocos2d/core/CCNode.js Outdated Show resolved Hide resolved
cocos2d/core/CCNode.js Outdated Show resolved Hide resolved
@jareguo jareguo changed the base branch from master to v2.4.3-release Aug 10, 2020
@holycanvas holycanvas changed the title 修改 cc.Node 的 setPosition() 和 setScale() 的默认行为. Don't change z value when invoke setPosition or setScale with two parameter Aug 11, 2020
@holycanvas holycanvas merged commit 10ef2e7 into cocos:v2.4.3-release Aug 11, 2020
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants