-
Notifications
You must be signed in to change notification settings - Fork 29
Drawing
Punity can currently draw following primitives:
- Pixel (
pixel_draw
) - Line (
line_draw
) - Rectangle (filled) (
rect_draw
) - Rectangle (frame and fill) (
frame_draw
) - Bitmap (
bitmap_draw
) - Text (
text_draw
)
Some of the draw functions use properties set in CORE->canvas
:
-
clip
is aRect
that specifies clip. Set withclip_set
which does additional checks. Also see otherclip_*
functions. -
translate_x
andCORE->canvas.translate_y
are used to translate the drawing operations. You can also usecamera_*
functions. -
font
is used intext_draw
to get the font. -
flags
is used to set additional properties for bitmap drawing like horizontal or vertical flip, or mask that will cause every non-transparent pixel to be drawn with color set inCORE->canvas.mask
(this is how text is being drawn, for example).
Along with standard painter's algorithm drawing, Punity also supports deferred sorted drawing via draw list. All primitives (except for pixel_draw
) are available. Function names are the same, but sport a _push
suffix and one additional argument for z
coordinate at the end. So for example compare the two calls:
// Standard call.
rect_draw(rect_make(0, 0, 50, 50), 1);
// Draw-list call with z = 12.
rect_draw_push(rect_make(0, 0, 50, 50), 1, 12);
The lower z
, the sooner the draw operation is made. The sorting is stable, that means that if two draw commands have the same z
coordinate, they will be drawn in the call order.
Each draw command also carries a copy of Canvas
, so all the properties set to CORE->canvas
are kept and applied.
By default, CORE->draw_list
is used to store the draw commands. This draw list is automatically initialized and drawn each frame.