DrawUtilities. TileSlice

A tile drawn as a box of any size, kept as a style to draw with, like a UI skin

  • 9 slices is a nine-slice from the 3x3 block of tiles at tileInfo, see drawNineSlice
  • 3 slices is a three-slice from the 3 tiles in a row at tileInfo, see drawThreeSlice
  • 1 slice is the whole tile stretched over the box, a plain image
  • The UI system draws a widget's background with one, see uiSystem.defaultSlice

Constructor

new TileSlice(tileInfo, slicesopt, borderSizeopt, extraSpaceopt)

Create a tile slice style

Parameters:
NameTypeAttributesDefaultDescription
tileInfoTileInfo

The tile, or the first of the tiles, to draw with

slicesnumber<optional>
9

9 for a nine-slice, 3 for a three-slice, 1 for the whole tile

borderSizenumber<optional>

Drawn thickness of the edges and corners, undefined for the draw's own default

extraSpacenumber<optional>

Extra spacing adjustment of the slices, undefined for the draw's own default

Example
const panel = new TileSlice(tile(0, 16), 9, .5); // a border of half a world unit
panel.draw(vec2(0, 5), vec2(10, 4));
uiSystem.defaultSlice = new TileSlice(tile(0, 16), 9, 16); // UI sizes are pixels, every widget made after this

Members

borderSize :number|undefined

Type:
  • number | undefined
Properties
TypeDescription
number | undefined

Drawn thickness of the edges and corners, undefined for the draw's default

extraSpace :number|undefined

Type:
  • number | undefined
Properties
TypeDescription
number | undefined

Extra spacing adjustment of the slices, undefined for the draw's default

slices

Properties
TypeDescription
number

9 for a nine-slice, 3 for a three-slice, 1 for the whole tile

tileInfo

Properties
TypeDescription
TileInfo

The tile, or the first of the tiles, to draw with

Methods

draw(pos, size, coloropt, additiveColoropt, angleopt, useWebGLopt, screenSpaceopt, contextopt)

Draw it as a box in world space, or in screen space

Parameters:
NameTypeAttributesDefaultDescription
posVector2

Center position

sizeVector2

Size of the box

colorColor<optional>

Color to modulate with

additiveColorColor<optional>

Additive color

anglenumber<optional>
0

Angle to rotate by

useWebGLboolean<optional>
glEnable

Use WebGL for rendering

screenSpaceboolean<optional>
drawScreenSpace

Are pos and size in screen space?

contextCanvasRenderingContext2D | OffscreenCanvasRenderingContext2D<optional>

Canvas context to use

drawScreen(pos, size, coloropt, additiveColoropt, angleopt, useWebGLopt, contextopt)

Draw it as a box in screen space, with the 2D context by default, on top of what WebGL drew, like drawTextScreen

Parameters:
NameTypeAttributesDefaultDescription
posVector2

Screen space center position

sizeVector2

Screen space size

colorColor<optional>

Color to modulate with

additiveColorColor<optional>

Additive color

anglenumber<optional>
0

Angle to rotate by

useWebGLboolean<optional>
false

Use WebGL for rendering

contextCanvasRenderingContext2D | OffscreenCanvasRenderingContext2D<optional>

Canvas context to use