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
A 2D game object, inherited by all 2D-related nodes. Has a position, rotation, scale, and Z index.
描述
A 2D game object, with a transform (position, rotation, and scale). All 2D nodes, including physics objects and sprites, inherit from Node2D. Use Node2D as a parent node to move, scale and rotate children in a 2D project. Also gives control of the node's render order.
属性
方法
void | apply_scale ( ratio: Vector2 ) |
float | get_angle_to ( point: Vector2 ) const1 |
Transform2D | get_relative_transform_to_parent ( parent: Node ) const1 |
void | global_translate ( offset: Vector2 ) |
void | look_at ( point: Vector2 ) |
void | move_local_x ( delta: float , scaled: bool = false ) |
void | move_local_y ( delta: float , scaled: bool = false ) |
void | rotate ( radians: float ) |
Vector2 | to_global ( local_point: Vector2 ) const1 |
Vector2 | to_local ( global_point: Vector2 ) const1 |
void | translate ( offset: Vector2 ) |
属性说明
Vector2
global_position
Global position. See also position
.
float
global_rotation
Global rotation in radians. See also rotation
.
float
global_rotation_degrees
Helper property to access global_rotation
in degrees instead of radians. See also rotation_degrees
.
Vector2
global_scale
Global scale. See also scale
.
float
global_skew
Global skew in radians. See also skew
.
Transform2D
global_transform
void
set_global_transform ( value:Transform2D
)Transform2D
get_global_transform ( )
Global Transform2D
. See also transform
.
Vector2
position = Vector2(0, 0)
Position, relative to the node's parent. See also global_position
.
float
rotation = 0.0
Rotation in radians, relative to the node's parent. See also global_rotation
.
Note: This property is edited in the inspector in degrees. If you want to use degrees in a script, use rotation_degrees
.
float
rotation_degrees
Helper property to access rotation
in degrees instead of radians. See also global_rotation_degrees
.
Vector2
scale = Vector2(1, 1)
The node's scale, relative to the node's parent. Unscaled value: (1, 1)
. See also global_scale
.
Note: Negative X scales in 2D are not decomposable from the transformation matrix. Due to the way scale is represented with transformation matrices in Godot, negative scales on the X axis will be changed to negative scales on the Y axis and a rotation of 180 degrees when decomposed.
float
skew = 0.0
If set to a non-zero value, slants the node in one direction or another. This can be used for pseudo-3D effects. See also global_skew
.
Note: Skew is performed on the X axis only, and between rotation and scaling.
Note: This property is edited in the inspector in degrees. If you want to use degrees in a script, use skew = deg_to_rad(value_in_degrees)
.
Transform2D
transform
void
set_transform ( value:Transform2D
)Transform2D
get_transform ( )
The node's Transform2D
, relative to the node's parent. See also global_transform
.
方法说明
void
apply_scale ( ratio: Vector2
)
Multiplies the current scale by the ratio
vector.
float
get_angle_to ( point: Vector2
) const1
Returns the angle between the node and the point
in radians.
Illustration of the returned angle.
Transform2D
get_relative_transform_to_parent ( parent: Node
) const1
Returns the Transform2D
relative to this node's parent.
void
global_translate ( offset: Vector2
)
Adds the offset
vector to the node's global position.
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.
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 based on the Node._process
's delta
. If scaled
is false
, normalizes the movement.
void
move_local_y ( delta: float
, scaled: bool
= false )
Applies a local translation on the node's Y axis based on the Node._process
's delta
. If scaled
is false
, normalizes the movement.
void
rotate ( radians: float
)
Applies a rotation to the node, in radians, starting from its current rotation.
Vector2
to_global ( local_point: Vector2
) const1
Transforms the provided local position into a position in global coordinate space. The input is expected to be local relative to the Node2D it is called on. e.g. Applying this method to the positions of child nodes will correctly transform their positions into the global coordinate space, but applying it to a node's own position will give an incorrect result, as it will incorporate the node's own transformation into its global position.
Vector2
to_local ( global_point: Vector2
) const1
Transforms the provided global position into a position in local coordinate space. The output will be local relative to the Node2D it is called on. e.g. It is appropriate for determining the positions of child nodes, but it is not appropriate for determining its own position relative to its parent.
void
translate ( offset: Vector2
)
Translates the node by the given offset
in local coordinates.
本方法通常需要用户覆盖才能生效。
本方法无副作用,不会修改该实例的任何成员变量。
本方法除了能接受在此处描述的参数外,还能够继续接受任意数量的参数。
本方法用于构造某个类型。
调用本方法无需实例,可直接使用类名进行调用。
本方法描述的是使用本类型作为左操作数的有效运算符。
这个值是由下列位标志构成位掩码的整数。
无返回值。