Draw

Methods
19
Fields
None

Methods

MethodReturnsDescription
screenText(number, number, string, Color)()Text at a canvas position, its top-left corner at (x, y): y is the top edge of the text, not its baseline.
screenLine(number, number, number, number, Color, number)()A line between two canvas positions.
screenRect(number, number, number, number, Color)()A rectangle outline in canvas space.
screenRectFilled(number, number, number, number, Color)()A filled rectangle in canvas space.
tilePoly(WorldPoint, Color, Color)()A tile's outline and fill on the ground.
textAtWorld(WorldPoint, string, Color)()Text centred on a tile.
lineWorld(WorldPoint, WorldPoint, Color, number?)()A line between two tiles' centres. Both have to be in the loaded scene.
lineWorldFine(FinePoint, FinePoint, Color, number)()A line between two sub-tile points, for edges and corners.
renderText(ScreenAnchor, string, Color, number?)()Text centred on a projected point.
worldArrow(ScreenAnchor, ScreenAnchor, Color, number, boolean, boolean)()An arrow between two projected points.
worldToScreen(WorldPoint, number?)ScreenAnchor?A point to hand renderText or worldArrow. Whether it is on screen is decided when it is drawn, so it stays on its tile as the camera tu…
worldToScreenFine(number, number, number)ScreenAnchor?worldToScreen of a sub-tile point.
worldToScreenArea(WorldPoint, number, number, number?)ScreenAnchor?worldToScreen of the centre of a multi-tile footprint, so a label sits on the middle of a big NPC rather than its corner.
tileCorners(WorldPoint){ FinePoint }?A tile's four ground corners, for drawing edges rather than the whole tile.
fillTiles({ WorldPoint }, Color, Color)()Fill many tiles in one call.
tileEdges({ TileEdgeSpec }, Color, number)()Draw individual tile edges -- walls, collision boundaries, the outline of a region -- in one call.
hudBlock("top_left" | "top_right" | "bottom_left" | "bottom_right", number, number, "low" | "normal" | "high", (Draw) -> ())()Draw into a HUD panel pinned to a screen corner, laid out so it does not overlap infoboxes or other panels. Coordinates in the body are the…
record((Draw) -> ())PrimBufferBake drawing into a buffer that can be replayed.
replay(PrimBuffer)()Draw a recorded buffer again.

Method details

screenText

screenText: (Draw, number, number, string, Color) -> ()

Text at a canvas position, its top-left corner at (x, y): y is the top edge of the text, not its baseline.

x
Canvas x of the text's left edge.
y
Canvas y of the text's top edge.
text
What to draw.
color
The text colour.

screenLine

screenLine: (Draw, number, number, number, number, Color, number) -> ()

A line between two canvas positions.

x1
Start x.
y1
Start y.
x2
End x.
y2
End y.
color
The line colour.
thickness
Line width in pixels.

screenRect

screenRect: (Draw, number, number, number, number, Color) -> ()

A rectangle outline in canvas space.

x
Left.
y
Top.
width
Width.
height
Height.
color
The outline colour.

screenRectFilled

screenRectFilled: (Draw, number, number, number, number, Color) -> ()

A filled rectangle in canvas space.

x
Left.
y
Top.
width
Width.
height
Height.
color
The fill colour.

tilePoly

tilePoly: (Draw, WorldPoint, Color, Color) -> ()

A tile's outline and fill on the ground.

tile
The tile.
stroke
Outline colour.
fill
Fill colour; a zero alpha draws no fill.

lineWorld

lineWorld: (Draw, WorldPoint, WorldPoint, Color, number?) -> ()

A line between two tiles' centres. Both have to be in the loaded scene.

from
Start tile.
to
End tile.
color
The line colour.
thickness
Line width in pixels. Defaults to 1.5.

lineWorldFine

lineWorldFine: (Draw, FinePoint, FinePoint, Color, number) -> ()

A line between two sub-tile points, for edges and corners.

from
Start, in fine scene coordinates.
to
End, in fine scene coordinates.
color
The line colour.
thickness
Line width in pixels.

renderText

renderText: (Draw, ScreenAnchor, string, Color, number?) -> ()

Text centred on a projected point.

at
A point from worldToScreen.
text
What to draw.
color
The text colour.
liftPixels
Pixels above the point, so several labels on one entity do not overlap. Defaults to 0.

worldArrow

worldArrow: (Draw, ScreenAnchor, ScreenAnchor, Color, number, boolean, boolean) -> ()

An arrow between two projected points.

from
A point from worldToScreen.
to
A point from worldToScreen.
color
The arrow colour.
thickness
Line width in pixels.
headAtStart
Draw a head at the start.
headAtEnd
Draw a head at the end.

worldToScreen

worldToScreen: (Draw, WorldPoint, number?) -> ScreenAnchor?

A point to hand renderText or worldArrow. Whether it is on screen is decided when it is drawn, so it stays on its tile as the camera turns.

tile
The tile.
raise
How far above the ground, in fine units. Defaults to 0.
Returns
nil when logged out, or the tile is outside the loaded scene.

worldToScreenFine

worldToScreenFine: (Draw, number, number, number) -> ScreenAnchor?

worldToScreen of a sub-tile point.

px
Fine x.
height
Height above the ground.
pz
Fine z.
Returns
nil when logged out.

worldToScreenArea

worldToScreenArea: (Draw, WorldPoint, number, number, number?) -> ScreenAnchor?

worldToScreen of the centre of a multi-tile footprint, so a label sits on the middle of a big NPC rather than its corner.

tile
The south-west tile.
width
Footprint width in tiles.
height
Footprint height in tiles.
raise
How far above the ground, in fine units. Defaults to 0.
Returns
nil when logged out, or the tile is outside the loaded scene.

tileCorners

tileCorners: (Draw, WorldPoint) -> { FinePoint }?

A tile's four ground corners, for drawing edges rather than the whole tile.

tile
The tile.
Returns
Corners south-west, south-east, north-east, north-west, or nil when logged out, or the tile is outside the loaded scene.

tileEdges

tileEdges: (Draw, { TileEdgeSpec }, Color, number) -> ()

Draw individual tile edges -- walls, collision boundaries, the outline of a region -- in one call.

edges
Entries of { tile = WorldPoint, side = TileSide }.
color
The line colour.
thickness
Line width in pixels.

hudBlock

hudBlock: (Draw, "top_left" | "top_right" | "bottom_left" | "bottom_right", number, number, "low" | "normal" | "high", (Draw) -> ()) -> ()

Draw into a HUD panel pinned to a screen corner, laid out so it does not overlap infoboxes or other panels. Coordinates in the body are the panel's own.

Inside record or another hudBlock this draws nothing: a panel has to be drawn straight from the frame's own draw.

corner
Which corner. Another string raises.
width
Panel width.
height
Panel height.
priority
Its order against other blocks. Another string raises.
body
Called immediately, with the panel's own draw.

record

record: (Draw, (Draw) -> ()) -> PrimBuffer

Bake drawing into a buffer that can be replayed.

Geometry that only changes on a game tick costs a lot to rebuild every frame. Record it once and replay it until it changes. Text drawn in the body is dropped: a buffer holds geometry only.

body
Called immediately, with a recording draw.