From a39badcfea91eae36d8c494fa2ed47ddcdef5a4f Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Fri, 30 Oct 2020 15:20:11 +0800 Subject: [PATCH] add angle property for 2d (#7515) * add angle property * add angle api doc --- cocos/core/scene-graph/node.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/cocos/core/scene-graph/node.ts b/cocos/core/scene-graph/node.ts index db1d4641ae..a81c7ed398 100644 --- a/cocos/core/scene-graph/node.ts +++ b/cocos/core/scene-graph/node.ts @@ -206,6 +206,25 @@ export class Node extends BaseNode { return this._euler; } + /** + * @en Rotation in local coordinate system, represented by euler angles, but limited on z axis + * @zh 本地坐标系下的旋转,用欧拉角表示,但是限定在 z 轴上。 + */ + @editable + get angle () { + return this._euler.z; + } + set angle (val: number) { + Vec3.set(this._euler, 0, 0, val); + Quat.fromAngleZ(this._lrot, val); + this._eulerDirty = false; + + this.invalidateChildren(TransformBit.ROTATION); + if (this._eventMask & TRANSFORM_ON) { + this.emit(SystemEventType.TRANSFORM_CHANGED, TransformBit.ROTATION); + } + } + /** * @en Rotation in world coordinate system, represented by a quaternion * @zh 世界坐标系下的旋转,用四元数表示