Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
CanvasItem¶
2D 空间中所有对象的抽象基类。
Description¶
2D 空间中所有对象的抽象基类。画布项目(Canvas Item)以树状排列;子节点继承并扩展其父节点的变换。CanvasItem 由 Control 扩展为 GUI 相关的节点,由 Node2D 扩展为 2D 游戏对象。
任何 CanvasItem 都可以进行绘图。绘图时,引擎会调用 queue_redraw,然后节点就会在空闲时接收到请求重绘的 NOTIFICATION_DRAW。因此画布项目不需要每一帧都重绘,显著提升了性能。这个类还提供了几个用于在 CanvasItem 上绘图的函数(见 draw_*
函数)。不过这些函数都只能在 _draw 及其对应的 Object._notification 或连接到 draw 的方法内使用。
画布项目是按树状顺序绘制的。默认情况下,子项目位于父项目的上方,因此根 CanvasItem 将被画在所有项目的后面。这种行为可以针对单个画布项目进行更改。
CanvasItem 可以隐藏,隐藏时也会隐藏其子项目。通过调整画布项目的各种其它属性,你还可以调制它的颜色(通过 modulate 或 self_modulate)、更改 Z 索引、混合模式等。
Tutorials¶
Properties¶
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Methods¶
void |
_draw ( ) virtual |
void |
draw_animation_slice ( float animation_length, float slice_begin, float slice_end, float offset=0.0 ) |
void |
draw_arc ( Vector2 center, float radius, float start_angle, float end_angle, int point_count, Color color, float width=-1.0, bool antialiased=false ) |
void |
draw_char ( Font font, Vector2 pos, String char, int font_size=16, Color modulate=Color(1, 1, 1, 1) ) const |
void |
draw_char_outline ( Font font, Vector2 pos, String char, int font_size=16, int size=-1, Color modulate=Color(1, 1, 1, 1) ) const |
void |
draw_circle ( Vector2 position, float radius, Color color ) |
void |
draw_colored_polygon ( PackedVector2Array points, Color color, PackedVector2Array uvs=PackedVector2Array(), Texture2D texture=null ) |
void |
draw_dashed_line ( Vector2 from, Vector2 to, Color color, float width=-1.0, float dash=2.0, bool aligned=true ) |
void |
|
void |
draw_lcd_texture_rect_region ( Texture2D texture, Rect2 rect, Rect2 src_rect, Color modulate=Color(1, 1, 1, 1) ) |
void |
draw_line ( Vector2 from, Vector2 to, Color color, float width=-1.0, bool antialiased=false ) |
void |
draw_mesh ( Mesh mesh, Texture2D texture, Transform2D transform=Transform2D(1, 0, 0, 1, 0, 0), Color modulate=Color(1, 1, 1, 1) ) |
void |
draw_msdf_texture_rect_region ( Texture2D texture, Rect2 rect, Rect2 src_rect, Color modulate=Color(1, 1, 1, 1), float outline=0.0, |