Node2D
继承: CanvasItem < Node < Object
派生: AnimatedSprite2D, AudioListener2D, AudioStreamPlayer2D, BackBufferCopy, Bone2D, Camera2D, CanvasGroup, CanvasModulate, CollisionObject2D, CollisionPolygon2D, CollisionShape2D, CPUParticles2D, GPUParticles2D, Joint2D, Light2D, LightOccluder2D, Line2D, Marker2D, MeshInstance2D, MultiMeshInstance2D, NavigationLink2D, NavigationObstacle2D, NavigationRegion2D, Parallax2D, ParallaxLayer, Path2D, PathFollow2D, Polygon2D, RayCast2D, RemoteTransform2D, ShapeCast2D, Skeleton2D, Sprite2D, TileMap, TileMapLayer, TouchScreenButton, VisibleOnScreenNotifier2D
2D 游戏对象,被所有 2D 相关的节点继承。具有位置、旋转、缩放和倾斜。
描述
2D 游戏对象,具有变换(位置、旋转、缩放)。包括物理对象和精灵在内的所有 2D 节点都继承自 Node2D。可以使用 Node2D 作为父节点来移动、缩放和旋转 2D 项目中的子节点。还可以控制该节点的渲染顺序。
注意:Node2D 和 Control 都继承自 CanvasItem,它们都具有该类的 CanvasItem.z_index、CanvasItem.visible 等属性。
教程
属性
|
||
|
||
|
||
|
||
方法
void |
apply_scale(ratio: Vector2) |
get_angle_to(point: Vector2) const |
|
get_relative_transform_to_parent(parent: Node) const |
|
void |
global_translate(offset: Vector2) |
void |
|
void |
move_local_x(delta: float, scaled: bool = false) |
void |
move_local_y(delta: float, scaled: bool = false) |
void |
|
void |
属性说明
全局位置。另见 position。
全局旋转,单位为弧度。另见 rotation。
float global_rotation_degrees 🔗
辅助属性,用于按度数访问 global_rotation 而不是弧度数。另见 rotation_degrees。
全局缩放。另见 scale。
全局偏斜,单位为弧度。另见 skew。
Transform2D global_transform 🔗
void set_global_transform(value: Transform2D)
Transform2D get_global_transform()
全局 Transform2D。另见 transform。
Vector2 position = Vector2(0, 0) 🔗
位置,相对于父节点。另见 global_position。
旋转,单位为弧度,相对于该节点的父节点。另见 global_rotation。
注意:这个属性在检查器中是以度数编辑的。如果你想在脚本中使用度数,请使用 rotation_degrees。
辅助属性,用于按度数访问 rotation 而不是弧度数。另见 global_rotation_degrees。
Vector2 scale = Vector2(1, 1) 🔗
该节点的缩放,相对于父节点。未缩放值:(1, 1)。另见 global_scale。
注意:2D 中,变换矩阵是无法分解出负数的 X 缩放的。由于 Godot 中使用变换矩阵来表示缩放,X 轴上的负数缩放在分解后会变为 Y 轴的负数缩放和一次 180 度的旋转。
如果设为非零值,则节点会向某一方向倾斜。可以用来实现伪 3D 效果。另见 global_skew。
注意:只有 X 轴会执行倾斜,发生在旋转和缩放中间。
注意:该属性在检查器中以度为单位进行编辑。如果你想在脚本中使用度数,请使用 skew = deg_to_rad(value_in_degrees)。
Transform2D transform 🔗
void set_transform(value: Transform2D)
Transform2D get_transform()
该节点的 Transform2D,相对于父节点。另见 global_transform。
方法说明
void apply_scale(ratio: Vector2) 🔗
将当前缩放乘以比例向量 ratio。
float get_angle_to(point: Vector2) const 🔗
Returns the angle between the node and the point in radians. See also look_at().
Illustration of the returned angle.
Transform2D get_relative_transform_to_parent(parent: Node) const 🔗
返回相对于此节点的父节点的 Transform2D。
void global_translate(offset: Vector2) 🔗
将偏移向量 offset 添加到该节点的全局位置。
void look_at(point: Vector2) 🔗
Rotates the node so that its local +X axis points towards the point, which is expected to use global coordinates. This method is a combination of both rotate() and get_angle_to().
point should not be the same as the node's position, otherwise the node always looks to the right.
void move_local_x(delta: float, scaled: bool = false) 🔗
Applies a local translation on the node's X axis with the amount specified in delta. If scaled is false, normalizes the movement to occur independently of the node's scale.
void move_local_y(delta: float, scaled: bool = false) 🔗
Applies a local translation on the node's Y axis with the amount specified in delta. If scaled is false, normalizes the movement to occur independently of the node's scale.
Applies a rotation to the node, in radians, starting from its current rotation. This is equivalent to rotation += radians.
Vector2 to_global(local_point: Vector2) const 🔗
将提供的本地位置转换为全局坐标空间的位置。例如,对子节点的位置应用这个方法将正确地把它们的位置转换到全局坐标空间,但对节点自己的位置应用这个方法将得到一个不正确的结果,因为它将把节点自己的变换纳入它的全局位置。
Vector2 to_local(global_point: Vector2) const 🔗
将提供的全局位置转换为本地坐标空间的位置。例如,它适合于确定子节点的位置,但不适合于确定其自身相对于父节点的位置。
void translate(offset: Vector2) 🔗
Translates the node by the given offset in local coordinates. This is equivalent to position += offset.