Node2D

Hereda: CanvasItem < Node < Object

Heredado por: 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 skew.

Descripción

Un objeto de juego 2D, con una transformación (posición, rotación y escala). Todos los nodos 2D, incluyendo los objetos de física y los sprites, heredan de Node2D. Utiliza Node2D como nodo padre para mover, escalar y rotar a los hijos en un proyecto 2D. También da control del orden de renderizado del nodo.

Nota: Ya que tanto Node2D como Control heredan de CanvasItem, comparten varios conceptos de la clase, como las propiedades CanvasItem.z_index y CanvasItem.visible.

Tutoriales

Propiedades

Vector2

global_position

float

global_rotation

float

global_rotation_degrees

Vector2

global_scale

float

global_skew

Transform2D

global_transform

Vector2

position

Vector2(0, 0)

float

rotation

0.0

float

rotation_degrees

Vector2

scale

Vector2(1, 1)

float

skew

0.0

Transform2D

transform

Métodos

void

apply_scale(ratio: Vector2)

float

get_angle_to(point: Vector2) const

Transform2D

get_relative_transform_to_parent(parent: Node) const

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) const

Vector2

to_local(global_point: Vector2) const

void

translate(offset: Vector2)


Descripciones de Propiedades

Vector2 global_position 🔗

  • void set_global_position(value: Vector2)

  • Vector2 get_global_position()

Posición global. Véase también position.


float global_rotation 🔗

  • void set_global_rotation(value: float)

  • float get_global_rotation()

Rotación global en radianes. Véase también rotation.


float global_rotation_degrees 🔗

  • void set_global_rotation_degrees(value: float)

  • float get_global_rotation_degrees()

Propiedad de ayuda para acceder a global_rotation en grados en lugar de radianes. Véase también rotation_degrees.


Vector2 global_scale 🔗

Escala global. Véase también scale.


float global_skew 🔗

  • void set_global_skew(value: float)

  • float get_global_skew()

Global skew in radians. See also skew.


Transform2D 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 🔗

  • void set_rotation(value: float)

  • float get_rotation()

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 🔗

  • void set_rotation_degrees(value: float)

  • float get_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 🔗

La Transform2D del nodo, relativa a su nodo padre. Véase también global_transform.


Descripciones de Métodos

void apply_scale(ratio: Vector2) 🔗

Multiplica la escala actual por el vector ratio.


float get_angle_to(point: Vector2) const 🔗

Devuelve el ángulo entre el nodo y el point en radianes.

Ilustración del ángulo devuelto.


Transform2D get_relative_transform_to_parent(parent: Node) const 🔗

Devuelve el Transform2D relativo al padre de este nodo.


void global_translate(offset: Vector2) 🔗

Añade el vector offset a la posición global del nodo.


void look_at(point: Vector2) 🔗

Rota el nodo para que su eje +X local apunte hacia el point, que se espera que use coordenadas globales.

El point no debe ser el mismo que la posición del nodo, de lo contrario el nodo siempre mirará hacia la derecha.


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.


void rotate(radians: float) 🔗

Aplica una rotación al nodo, en radianes, a partir de su rotación actual.


Vector2 to_global(local_point: Vector2) const 🔗

Transforma la posición local proporcionada en una posición en el espacio de coordenadas globales. Se espera que la entrada sea local en relación con el Node2D al que se llama. Por ejemplo, aplicar este método a las posiciones de los nodos hijos transformará correctamente sus posiciones en el espacio de coordenadas globales, pero aplicarlo a la propia posición de un nodo dará un resultado incorrecto, ya que incorporará la propia transformación del nodo en su posición global.


Vector2 to_local(global_point: Vector2) const 🔗

Transforma la posición global proporcionada en una posición en el espacio de coordenadas locales. La salida será local en relación con el Node2D al que se llama. Por ejemplo, es apropiado para determinar las posiciones de los nodos hijos, pero no es apropiado para determinar su propia posición en relación con su padre.


void translate(offset: Vector2) 🔗

Traslada el nodo por el offset dado en coordenadas locales.