Struct CanvasItem

Base class of anything 2D.

struct CanvasItem ;

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, 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 draw_* functions). However, they can only be used inside the GodotObject.notification, signal or 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.

Properties

NameTypeDescription
lightMask[get, set] longThe rendering layers in which this CanvasItem responds to Light2D nodes.
modulate[get, set] ColorThe color applied to textures on this CanvasItem.
selfModulate[get, set] ColorThe color applied to textures on this CanvasItem. This is not inherited by children CanvasItems.
showBehindParent[get, set] boolIf true, the object draws behind its parent.
showOnTop[get, set] boolIf true, the object draws on top of its parent.
useParentMaterial[get, set] boolIf true, the parent CanvasItem's material property is used as this one's material.
visible[get, set] boolIf true, this CanvasItem is drawn. For controls that inherit Popup, the correct way to make them visible is to call one of the multiple popup*() functions instead.

Methods

NameDescription
_draw Overridable function called by the engine (if defined) to draw the canvas item.
_editGetPivot
_editGetPosition
_editGetRect
_editGetRotation
_editGetScale
_editGetState
_editGetTransform
_editSetPivot
_editSetPosition
_editSetRect
_editSetRotation
_editSetScale
_editSetState
_editUsePivot
_editUseRect
_editUseRotation
_isOnTop
_setOnTop
_toplevelRaiseSelf
_updateCallback
drawArc Draws an arc between the given angles. The larger the value of point_count, the smoother the curve.
drawChar Draws a string character using a custom font. Returns the advance, depending on the character width and kerning with an optional next character.
drawCircle Draws a colored circle.
drawColoredPolygon Draws a colored polygon of any amount of points, convex or concave.
drawLine Draws a line from a 2D point to another, with a given color and width. It can be optionally antialiased.
drawMesh Draws a Mesh in 2D, using the provided texture. See MeshInstance2D for related documentation.
drawMultiline Draws multiple, parallel lines with a uniform color. width and antialiased are currently not implemented and have no effect.
drawMultilineColors Draws multiple, parallel lines with a uniform width, segment-by-segment coloring, and optional antialiasing. Colors assigned to line segments match by index between points and colors.
drawMultimesh Draws a MultiMesh in 2D with the provided texture. See MultiMeshInstance2D for related documentation.
drawPolygon Draws a polygon of any amount of points, convex or concave.
drawPolyline Draws interconnected line segments with a uniform color and width and optional antialiasing.
drawPolylineColors 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.
drawPrimitive 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.
drawRect 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.
drawSetTransform Sets a custom transform for drawing via components. Anything drawn afterwards will be transformed by this.
drawSetTransformMatrix Sets a custom transform for drawing via matrix. Anything drawn afterwards will be transformed by this.
drawString Draws a string using a custom font.
drawStyleBox Draws a styled rectangle.
drawTexture Draws a texture at a given position.
drawTextureRect 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.
drawTextureRectRegion 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.
forceUpdateTransform 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.
getCanvas Returns the RID of the World2D canvas where this item is in.
getCanvasItem Returns the canvas item RID used by VisualServer for this item.
getCanvasTransform Returns the transform matrix of this item's canvas.
getGlobalMousePosition Returns the global position of the mouse.
getGlobalTransform Returns the global transform matrix of this item.
getGlobalTransformWithCanvas Returns the global transform matrix of this item in relation to the canvas.
getLightMask
getLocalMousePosition Returns the mouse position relative to this item's position.
getMaterial
getModulate
getSelfModulate
getTransform Returns the transform matrix of this item.
getUseParentMaterial
getViewportRect Returns the viewport's boundaries as a Rect2.
getViewportTransform Returns this item's transform in relation to the viewport.
getWorld2d Returns the World2D where this item is in.
hide Hide the CanvasItem if it's currently visible.
isDrawBehindParentEnabled
isLocalTransformNotificationEnabled Returns true if local transform notifications are communicated to children.
isSetAsToplevel Returns true if the node is set as top-level. See setAsToplevel.
isTransformNotificationEnabled Returns true if global transform notifications are communicated to children.
isVisible
isVisibleInTree Returns true if the node is present in the SceneTree, its visible property is true and its inherited visibility is also true.
makeCanvasPositionLocal Assigns screen_point as this node's new local transform.
makeInputLocal Transformations issued by event's inputs are applied in local space instead of global space.
setAsToplevel If enable is true, the node won't inherit its transform from parent canvas items.
setDrawBehindParent
setLightMask
setMaterial
setModulate
setNotifyLocalTransform If enable is true, children will be updated with local transform data.
setNotifyTransform If enable is true, children will be updated with global transform data.
setSelfModulate
setUseParentMaterial
setVisible
show 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.
update Queue the CanvasItem for update. constant NOTIFICATION_DRAW will be called on idle time to request redraw.

Enums

NameDescription
BlendMode
Constants