mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
Node.x/y/z are back. (#18228)
It will be easier for just set one axis value. For example, while using Tween animation, we want to make a sprite jump up and down forever and move x to 100, it will be hard to do that if Node.x/y/z are absent.
This commit is contained in:
@@ -49,8 +49,9 @@ export const Node: typeof JsbNode = jsb.Node;
|
||||
export type Node = JsbNode;
|
||||
cclegacy.Node = Node;
|
||||
|
||||
const NodeCls: any = Node;
|
||||
const tempVec3 = new Vec3();
|
||||
|
||||
const NodeCls: any = Node;
|
||||
|
||||
NodeCls.reserveContentsForAllSyncablePrefabTag = reserveContentsForAllSyncablePrefabTag;
|
||||
|
||||
@@ -860,6 +861,39 @@ Object.defineProperty(nodeProto, 'position', {
|
||||
},
|
||||
});
|
||||
|
||||
Object.defineProperty(nodeProto, 'x', {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get(): number {
|
||||
return this._lpos.x;
|
||||
},
|
||||
set(v: number) {
|
||||
this.setPosition(v, this._lpos.y, this._lpos.z);
|
||||
},
|
||||
});
|
||||
|
||||
Object.defineProperty(nodeProto, 'y', {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get(): number {
|
||||
return this._lpos.y;
|
||||
},
|
||||
set(v: number) {
|
||||
this.setPosition(this._lpos.x, v, this._lpos.z);
|
||||
},
|
||||
});
|
||||
|
||||
Object.defineProperty(nodeProto, 'z', {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get(): number {
|
||||
return this._lpos.z;
|
||||
},
|
||||
set(v: number) {
|
||||
this.setPosition(this._lpos.x, this._lpos.y, v);
|
||||
},
|
||||
});
|
||||
|
||||
Object.defineProperty(nodeProto, 'rotation', {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
@@ -893,6 +927,48 @@ Object.defineProperty(nodeProto, 'worldPosition', {
|
||||
},
|
||||
});
|
||||
|
||||
Object.defineProperty(nodeProto, 'worldPositionX', {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get(): number {
|
||||
this.getWorldPosition(tempVec3);
|
||||
return tempVec3.x;
|
||||
},
|
||||
set(v: number) {
|
||||
this.getWorldPosition(tempVec3);
|
||||
tempVec3.x = v;
|
||||
this.setWorldPosition(tempVec3);
|
||||
},
|
||||
});
|
||||
|
||||
Object.defineProperty(nodeProto, 'worldPositionY', {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get(): number {
|
||||
this.getWorldPosition(tempVec3);
|
||||
return tempVec3.y;
|
||||
},
|
||||
set(v: number) {
|
||||
this.getWorldPosition(tempVec3);
|
||||
tempVec3.y = v;
|
||||
this.setWorldPosition(tempVec3);
|
||||
},
|
||||
});
|
||||
|
||||
Object.defineProperty(nodeProto, 'worldPositionZ', {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get(): number {
|
||||
this.getWorldPosition(tempVec3);
|
||||
return tempVec3.z;
|
||||
},
|
||||
set(v: number) {
|
||||
this.getWorldPosition(tempVec3);
|
||||
tempVec3.z = v;
|
||||
this.setWorldPosition(tempVec3);
|
||||
},
|
||||
});
|
||||
|
||||
Object.defineProperty(nodeProto, 'worldRotation', {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
|
||||
@@ -1592,6 +1592,54 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable {
|
||||
this.setPosition(val as Vec3);
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Get x axis value in local coordinate system
|
||||
* @zh 获取本地 x 轴坐标分量
|
||||
*/
|
||||
get x (): number {
|
||||
return this._lpos.x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Set x axis value in local coordinate system
|
||||
* @zh 设置本地 x 轴坐标分量
|
||||
*/
|
||||
set x (val: number) {
|
||||
this.setPosition(val, this._lpos.y, this._lpos.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Get y axis value in local coordinate system
|
||||
* @zh 获取本地 y 轴坐标分量
|
||||
*/
|
||||
get y (): number {
|
||||
return this._lpos.y;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Set y axis value in local coordinate system
|
||||
* @zh 设置本地 y 轴坐标分量
|
||||
*/
|
||||
set y (val: number) {
|
||||
this.setPosition(this._lpos.x, val, this._lpos.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Get z axis value in local coordinate system
|
||||
* @zh 获取本地 z 轴坐标分量
|
||||
*/
|
||||
get z (): number {
|
||||
return this._lpos.z;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Set z axis value in local coordinate system
|
||||
* @zh 设置本地 z 轴坐标分量
|
||||
*/
|
||||
set z (val: number) {
|
||||
this.setPosition(this._lpos.x, this._lpos.y, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Position in world coordinate system
|
||||
* @zh 世界坐标系下的坐标
|
||||
@@ -1606,6 +1654,57 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable {
|
||||
this.setWorldPosition(val as Vec3);
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Get x axis value in world coordinate system
|
||||
* @zh 获取世界坐标 x 轴分量
|
||||
*/
|
||||
get worldPositionX (): number {
|
||||
this.updateWorldTransform();
|
||||
return this._pos.x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Set x axis value in world coordinate system
|
||||
* @zh 设置世界坐标 x 轴分量
|
||||
*/
|
||||
set worldPositionX (val: number) {
|
||||
this.setWorldPosition(val, this._pos.y, this._pos.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Get y axis value in world coordinate system
|
||||
* @zh 获取世界坐标 y 轴分量
|
||||
*/
|
||||
get worldPositionY (): number {
|
||||
this.updateWorldTransform();
|
||||
return this._pos.y;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Set y axis value in world coordinate system
|
||||
* @zh 设置世界坐标 y 轴分量
|
||||
*/
|
||||
set worldPositionY (val: number) {
|
||||
this.setWorldPosition(this._pos.x, val, this._pos.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Get z axis value in world coordinate system
|
||||
* @zh 获取世界坐标 z 轴分量
|
||||
*/
|
||||
get worldPositionZ (): number {
|
||||
this.updateWorldTransform();
|
||||
return this._pos.z;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Set z axis value in world coordinate system
|
||||
* @zh 设置世界坐标 z 轴分量
|
||||
*/
|
||||
set worldPositionZ (val: number) {
|
||||
this.setWorldPosition(this._pos.x, this._pos.y, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Rotation in local coordinate system, represented by a quaternion
|
||||
* @zh 本地坐标系下的旋转,用四元数表示
|
||||
|
||||
Reference in New Issue
Block a user