Skip to main content
Drawing in the draw order

Drawing in the draw order

· One min read
Balaur

The render.draw_*_2d verbs take a trailing options table. Its z_index puts a shape among the nodes of that index, over them and under the next.

A sea at index 0, a ship at index 2, and a green circle and a white line drawn at index 1 between them; a red circle with no index draws over everything

  • #{ z_index: 1 } on draw_circle_2d, draw_rect_2d, draw_arc_2d, draw_polygon_2d, draw_polyline_2d, draw_texture_2d, draw_line_2d and draw_text_2d places the shape at that index. Without one it draws over the scene.
  • A stroke placed at an index is a mesh, so its width in pixels holds at the camera's zoom.
  • draw_texture_2d takes region_origin and region_size in the image's pixels and draws that part of it, the keys a sprite uses for its region.
  • A misspelt key is an error naming the keys a verb takes.
  • balaur import draws a Godot node's _draw at the node's global_z_index, and a draw_texture_rect_region through the region.
render::draw_circle_2d(-1.5, 0.0, 1.4, [0.2, 0.9, 0.4, 1.0], #{ z_index: 1 });
render::draw_texture_2d("art/blocks.png", -5.0, 2.2, 1.5, 1.5, (),
#{ region_origin: [0, 0], region_size: [16, 16] });