Base class of anything 2D. Base class of anything 2D. Canvas items are laid out in a tree; children inherit and extend their parent's transform. [CanvasItem] is extended by [Control] for anything GUI-related, and by [Node2D] for anything related to the 2D engine. Any [CanvasItem] can draw. For this, [method update] must be called, then [constant NOTIFICATION_DRAW] will be received on idle time to request redraw. Because of this, canvas items don't need to be redrawn on every frame, improving the performance significantly. Several functions for drawing on the [CanvasItem] are provided (see [code]draw_*[/code] functions). However, they can only be used inside the [method Object._notification], signal or [method _draw] virtual functions. Canvas items are drawn in tree order. By default, children are on top of their parents so a root [CanvasItem] will be drawn behind everything. This behavior can be changed on a per-item basis. A [CanvasItem] can also be hidden, which will also hide its children. It provides many ways to change parameters such as modulation (for itself and its children) and self modulation (only for itself), as well as its blend mode. Ultimately, a transform notification can be requested, which will notify the node that its global position changed in case the parent tree changed. [b]Note:[/b] Unless otherwise specified, all methods that have angle parameters must have angles specified as [i]radians[/i]. To convert degrees to radians, use [method @GDScript.deg2rad]. https://docs.godotengine.org/en/latest/tutorials/2d/2d_transforms.html https://docs.godotengine.org/en/latest/tutorials/2d/custom_drawing_in_2d.html Overridable function called by the engine (if defined) to draw the canvas item. Draws an arc between the given angles. The larger the value of [code]point_count[/code], the smoother the curve. Draws a string character using a custom font. Returns the advance, depending on the character width and kerning with an optional next character. Draws a colored circle. Draws a colored polygon of any amount of points, convex or concave. Draws a line from a 2D point to another, with a given color and width. Draws a [Mesh] in 2D, using the provided texture. See [MeshInstance2D] for related documentation. Draws multiple, parallel lines with a uniform [code]color[/code]. Draws multiple, parallel lines with a uniform [code]width[/code] and segment-by-segment coloring. Colors assigned to line segments match by index between [code]points[/code] and [code]colors[/code]. Draws a [MultiMesh] in 2D with the provided texture. See [MultiMeshInstance2D] for related documentation. Draws a polygon of any amount of points, convex or concave. Draws interconnected line segments with a uniform [code]color[/code] and [code]width[/code]. Draws interconnected line segments with a uniform [code]width[/code] and segment-by-segment coloring. Colors assigned to line segments match by index between [code]points[/code] and [code]colors[/code]. 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. Draws a rectangle. If [code]filled[/code] is [code]true[/code], the rectangle will be filled with the [code]color[/code] specified. If [code]filled[/code] is [code]false[/code], the rectangle will be drawn as a stroke with the [code]color[/code] and [code]width[/code] specified. [b]Note:[/b] [code]width[/code] is only effective if [code]filled[/code] is [code]false[/code]. 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. Draws [code]text[/code] using the specified [code]font[/code] at the [code]position[/code] (top-left corner). The text will have its color multiplied by [code]modulate[/code]. If [code]clip_w[/code] is greater than or equal to 0, the text will be clipped if it exceeds the specified width. [b]Example using the default project font:[/b] [codeblocks] [gdscript] # 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") [/gdscript] [csharp] // 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. Font defaultFont = new Control().GetFont("font"); DrawString(defaultFont, new Vector2(64, 64), "Hello world"); [/csharp] [/codeblocks] See also [method Font.draw]. Draws a styled rectangle. Draws a texture at a given position. Draws a textured rectangle at a given position, optionally modulated by a color. If [code]transpose[/code] is [code]true[/code], the texture will have its X and Y coordinates swapped. Draws a textured rectangle region at a given position, optionally modulated by a color. If [code]transpose[/code] is [code]true[/code], the texture will have its X and Y coordinates swapped. 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 [RenderingServer] 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. Returns the mouse position relative to this item's position. Returns the transform matrix of this item. 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. Returns [code]true[/code] if local transform notifications are communicated to children. Returns [code]true[/code] if the node is set as top-level. See [method set_as_toplevel]. Returns [code]true[/code] if global transform notifications are communicated to children. Returns [code]true[/code] if the node is present in the [SceneTree], its [member visible] property is [code]true[/code] and all its antecedents are also visible. If any antecedent is hidden, this node will not be visible in the scene tree. Assigns [code]screen_point[/code] as this node's new local transform. Transformations issued by [code]event[/code]'s inputs are applied in local space instead of global space. If [code]enable[/code] is [code]true[/code], the node won't inherit its transform from parent canvas items. If [code]enable[/code] is [code]true[/code], children will be updated with local transform data. If [code]enable[/code] is [code]true[/code], children will be updated with global transform data. 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 [code]popup*()[/code] functions instead. Queue the [CanvasItem] for update. [constant NOTIFICATION_DRAW] will be called on idle time to request redraw. 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]. The color applied to textures on this [CanvasItem]. This is not inherited by children [CanvasItem]s. If [code]true[/code], the object draws behind its parent. If [code]true[/code], the object draws on top of its parent. The texture filtering mode to use on this [CanvasItem]. The texture repeating mode to use on this [CanvasItem]. If [code]true[/code], the parent [CanvasItem]'s [member material] property is used as this one's material. If [code]true[/code], 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 [code]true[/code]). [b]Note:[/b] For controls that inherit [Popup], the correct way to make them visible is to call one of the multiple [code]popup*()[/code] functions instead. Emitted when the [CanvasItem] must redraw. This can only be connected realtime, as deferred will not allow drawing. Emitted when becoming hidden. Emitted when the item rect has changed. Emitted when the visibility (hidden/visible) changes. The [CanvasItem]'s transform has changed. This notification is only received if enabled by [method set_notify_transform] or [method set_notify_local_transform]. The [CanvasItem] is requested to draw. The [CanvasItem]'s visibility has changed. The [CanvasItem] has entered the canvas. The [CanvasItem] has exited the canvas. The [CanvasItem] will inherit the filter from its parent. The texture filter reads from the nearest pixel only. The simplest and fastest method of filtering. Useful for pixel art. The texture filter blends between the nearest four pixels. Use this for most cases where you want to avoid a pixelated style. The texture filter reads from the nearest pixel in the nearest mipmap. This is the fastest way to read from textures with mipmaps. The texture filter blends between the nearest 4 pixels and between the nearest 2 mipmaps. Use this for non-pixel art textures that may be viewed at a low scale (e.g. due to [Camera2D] zoom), as mipmaps are important to smooth out pixels that are smaller than on-screen pixels. The texture filter reads from the nearest pixel, but selects a mipmap based on the angle between the surface and the camera view. This reduces artifacts on surfaces that are almost in line with the camera. [b]Note:[/b] This texture filter is rarely useful in 2D projects. [constant TEXTURE_FILTER_NEAREST_WITH_MIPMAPS] is usually more appropriate. The texture filter blends between the nearest 4 pixels and selects a mipmap based on the angle between the surface and the camera view. This reduces artifacts on surfaces that are almost in line with the camera. This is the slowest of the filtering options, but results in the highest quality texturing. [b]Note:[/b] This texture filter is rarely useful in 2D projects. [constant TEXTURE_FILTER_LINEAR_WITH_MIPMAPS] is usually more appropriate. Represents the size of the [enum TextureFilter] enum. The [CanvasItem] will inherit the filter from its parent. Texture will not repeat. Texture will repeat normally. Texture will repeat in a 2x2 tiled mode, where elements at even positions are mirrored. Represents the size of the [enum TextureRepeat] enum.