Struct gdnative_bindings_lily::node_2d::Node2D[][src]

pub struct Node2D { /* fields omitted */ }
Expand description

core class Node2D inherits CanvasItem (unsafe).

Official documentation

See the documentation of this class in the Godot engine’s official documentation. The method descriptions are generated from it and typically contain code samples in GDScript, not Rust.

Memory management

Non reference counted objects such as the ones of this type are usually owned by the engine.

Node2D is a reference-only type. Persistent references can only exist in the unsafe Ref<Node2D> form.

In the cases where Rust code owns an object of this type, for example if the object was just created on the Rust side and not passed to the engine yet, ownership should be either given to the engine or the object must be manually destroyed using Ref::free, or Ref::queue_free if it is a Node.

Class hierarchy

Node2D inherits methods from:

Safety

All types in the Godot API have “interior mutability” in Rust parlance. To enforce that the official thread-safety guidelines are followed, the typestate pattern is used in the Ref and TRef smart pointers, and the Instance API. The typestate Access in these types tracks whether the access is unique, shared, or exclusive to the current thread. For more information, see the type-level documentation on Ref.

Implementations

Creates a new instance of this object.

Because this type is not reference counted, the lifetime of the returned object is not automatically managed.

Immediately after creation, the object is owned by the caller, and can be passed to the engine (in which case the engine will be responsible for destroying the object) or destroyed manually using Ref::free, or preferably Ref::queue_free if it is a Node.

Multiplies the current scale by the ratio vector.

Returns the angle between the node and the point in radians.

Global position.

Global rotation in radians.

Global rotation in degrees.

Global scale.

Position, relative to the node’s parent.

Returns the Transform2D relative to this node’s parent.

Rotation in radians, relative to the node’s parent.

Rotation in degrees, relative to the node’s parent.

The node’s scale. Unscaled value: (1, 1).

Z index. Controls the order in which the nodes render. A node with a higher Z index will display in front of others.

Adds the offset vector to the node’s global position.

If true, the node’s Z index is relative to its parent’s Z index. If this node’s Z index is 2 and its parent’s effective Z index is 3, then this node’s effective Z index will be 2 + 3 = 5.

Rotates the node so it points towards the point, which is expected to use global coordinates.

Applies a local translation on the node’s X axis based on the [method Node._process]’s delta. If scaled is false, normalizes the movement.

Default Arguments

  • scaled - false

Applies a local translation on the node’s Y axis based on the [method Node._process]’s delta. If scaled is false, normalizes the movement.

Default Arguments

  • scaled - false

Applies a rotation to the node, in radians, starting from its current rotation.

Global position.

Global rotation in radians.

Global rotation in degrees.

Global scale.

Global Transform2D.

Position, relative to the node’s parent.

Rotation in radians, relative to the node’s parent.

Rotation in degrees, relative to the node’s parent.

The node’s scale. Unscaled value: (1, 1).

Local Transform2D.

If true, the node’s Z index is relative to its parent’s Z index. If this node’s Z index is 2 and its parent’s effective Z index is 3, then this node’s effective Z index will be 2 + 3 = 5.

Z index. Controls the order in which the nodes render. A node with a higher Z index will display in front of others.

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.

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.

Translates the node by the given offset in local coordinates.

Methods from Deref<Target = CanvasItem>

Draws an arc between the given angles. The larger the value of point_count, the smoother the curve.

Default Arguments

  • width - 1.0
  • antialiased - false

Draws a string character using a custom font. Returns the advance, depending on the character width and kerning with an optional next character.

Default Arguments

  • modulate - Color( 1, 1, 1, 1 )

Draws a colored circle.

Draws a colored polygon of any amount of points, convex or concave.

Default Arguments

  • uvs - PoolVector2Array( )
  • texture - null
  • normal_map - null
  • antialiased - false

Draws a line from a 2D point to another, with a given color and width. It can be optionally antialiased.

Default Arguments

  • width - 1.0
  • antialiased - false

Draws a Mesh in 2D, using the provided texture. See MeshInstance2D for related documentation.

Default Arguments

  • normal_map - null
  • transform - Transform2D( 1, 0, 0, 1, 0, 0 )
  • modulate - Color( 1, 1, 1, 1 )

Draws multiple, parallel lines with a uniform color. Note: width and antialiased are currently not implemented and have no effect.

Default Arguments

  • width - 1.0
  • antialiased - false

Draws multiple, parallel lines with a uniform width and segment-by-segment coloring. Colors assigned to line segments match by index between points and colors. Note: width and antialiased are currently not implemented and have no effect.

Default Arguments

  • width - 1.0
  • antialiased - false

Draws a MultiMesh in 2D with the provided texture. See MultiMeshInstance2D for related documentation.

Default Arguments

  • normal_map - null

Draws a polygon of any amount of points, convex or concave.

Default Arguments

  • uvs - PoolVector2Array( )
  • texture - null
  • normal_map - null
  • antialiased - false

Draws interconnected line segments with a uniform color and width and optional antialiasing.

Default Arguments

  • width - 1.0
  • antialiased - false

Draws interconnected line segments with a uniform width, segment-by-segment coloring, and optional antialiasing. Colors assigned to line segments match by index between points and colors.

Default Arguments

  • width - 1.0
  • antialiased - false

Draws a custom primitive. 1 point for a point, 2 points for a line, 3 points for a triangle and 4 points for a quad.

Default Arguments

  • texture - null
  • width - 1.0
  • normal_map - null

Draws a rectangle. If filled is true, the rectangle will be filled with the color specified. If filled is false, the rectangle will be drawn as a stroke with the color and width specified. If antialiased is true, the lines will be antialiased. Note: width and antialiased are only effective if filled is false.

Default Arguments

  • filled - true
  • width - 1.0
  • antialiased - false

Sets a custom transform for drawing via components. Anything drawn afterwards will be transformed by this.

Sets a custom transform for drawing via matrix. Anything drawn afterwards will be transformed by this.

Sample code is GDScript unless otherwise noted.

Draws text using the specified font at the position (top-left corner). The text will have its color multiplied by modulate. If clip_w is greater than or equal to 0, the text will be clipped if it exceeds the specified width. Example using the default project font:

# If using this method in a script that redraws constantly, move the
# `default_font` declaration to a member variable assigned in `_ready()`
# so the Control is only created once.
var default_font = Control.new().get_font("font")
draw_string(default_font, Vector2(64, 64), "Hello world")

See also [method Font.draw].

Default Arguments

  • modulate - Color( 1, 1, 1, 1 )
  • clip_w - -1

Draws a styled rectangle.

Draws a texture at a given position.

Default Arguments

  • modulate - Color( 1, 1, 1, 1 )
  • normal_map - null

Draws a textured rectangle at a given position, optionally modulated by a color. If transpose is true, the texture will have its X and Y coordinates swapped.

Default Arguments

  • modulate - Color( 1, 1, 1, 1 )
  • transpose - false
  • normal_map - null

Draws a textured rectangle region at a given position, optionally modulated by a color. If transpose is true, the texture will have its X and Y coordinates swapped.

Default Arguments

  • modulate - Color( 1, 1, 1, 1 )
  • transpose - false
  • normal_map - null
  • clip_uv - true

Forces the transform to update. Transform changes in physics are not instant for performance reasons. Transforms are accumulated and then set. Use this if you need an up-to-date transform when doing physics operations.

Returns the [RID] of the World2D canvas where this item is in.

Returns the canvas item RID used by VisualServer for this item.

Returns the transform matrix of this item’s canvas.

Returns the global position of the mouse.

Returns the global transform matrix of this item.

Returns the global transform matrix of this item in relation to the canvas.

The rendering layers in which this CanvasItem responds to Light2D nodes.

Returns the mouse position relative to this item’s position.

The material applied to textures on this CanvasItem.

The color applied to textures on this CanvasItem.

The color applied to textures on this CanvasItem. This is not inherited by children CanvasItems.

Returns the transform matrix of this item.

If true, the parent CanvasItem’s [member material] property is used as this one’s material.

Returns the viewport’s boundaries as a Rect2.

Returns this item’s transform in relation to the viewport.

Returns the World2D where this item is in.

Hide the CanvasItem if it’s currently visible.

If true, the object draws behind its parent.

Returns true if local transform notifications are communicated to children.

Returns true if the node is set as top-level. See [method set_as_toplevel].

Returns true if global transform notifications are communicated to children.

If true, this CanvasItem is drawn. The node is only visible if all of its antecedents are visible as well (in other words, [method is_visible_in_tree] must return true). Note: For controls that inherit Popup, the correct way to make them visible is to call one of the multiple popup*() functions instead.

Returns true if the node is present in the SceneTree, its [member visible] property is true and all its antecedents are also visible. If any antecedent is hidden, this node will not be visible in the scene tree.

Assigns screen_point as this node’s new local transform.

Transformations issued by event’s inputs are applied in local space instead of global space.

If enable is true, the node won’t inherit its transform from parent canvas items.

If true, the object draws behind its parent.

The rendering layers in which this CanvasItem responds to Light2D nodes.

The material applied to textures on this CanvasItem.

The color applied to textures on this CanvasItem.

If enable is true, children will be updated with local transform data.

If enable is true, children will be updated with global transform data.

The color applied to textures on this CanvasItem. This is not inherited by children CanvasItems.

If true, the parent CanvasItem’s [member material] property is used as this one’s material.

If true, this CanvasItem is drawn. The node is only visible if all of its antecedents are visible as well (in other words, [method is_visible_in_tree] must return true). Note: For controls that inherit Popup, the correct way to make them visible is to call one of the multiple popup*() functions instead.

Show the CanvasItem if it’s currently hidden. For controls that inherit Popup, the correct way to make them visible is to call one of the multiple popup*() functions instead.

Queue the CanvasItem for update. [constant NOTIFICATION_DRAW] will be called on idle time to request redraw.

Trait Implementations

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

Mutably dereferences the value.

The memory management kind of this type. This modifies the behavior of the Ref smart pointer. See its type-level documentation for more information. Read more

Creates an explicitly null reference of Self as a method argument. This makes type inference easier for the compiler compared to Option. Read more

Creates a new instance of Self using a zero-argument constructor, as a Unique reference. Read more

Performs a dynamic reference downcast to target type. Read more

Performs a static reference upcast to a supertype that is guaranteed to be valid. Read more

Creates a persistent reference to the same Godot object with shared thread access. Read more

Creates a persistent reference to the same Godot object with thread-local thread access. Read more

Creates a persistent reference to the same Godot object with unique access. Read more

Recovers a instance ID previously returned by Object::get_instance_id if the object is still alive. See also TRef::try_from_instance_id. Read more

Recovers a instance ID previously returned by Object::get_instance_id if the object is still alive, and panics otherwise. This does NOT guarantee that the resulting reference is safe to use. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.