TextureSheets. TextureSheet

Texture Sheet - A texture that images are packed into as they load Uses shelf packing, images are placed left to right then wrap to a new row

Constructor

new TextureSheet(sizeopt)

Create a texture sheet, called automatically by loadSprite

Parameters:
NameTypeAttributesDescription
sizenumber<optional>

Width and height of the sheet in pixels

Members

canvas

Properties
TypeDescription
OffscreenCanvas

Canvas holding the packed images

context

Properties
TypeDescription
OffscreenCanvasRenderingContext2D

2d context for the canvas

cursor

Properties
TypeDescription
Vector2

Where the next image will be packed

glDirty

Properties
TypeDescription
boolean

Has the canvas changed since the last webgl upload?

rowHeight

Properties
TypeDescription
number

Height of the row being packed

size

Properties
TypeDescription
number

Width and height of the sheet in pixels

textureInfo

Properties
TypeDescription
TextureInfo

The texture info for this sheet

Methods

drawImage(image, tileInfo, updateopt, sourcePaddingopt)

Draw an image into this sheet at a tile returned by tryAdd

Parameters:
NameTypeAttributesDefaultDescription
imageHTMLImageElement

Source image to copy from

tileInfoTileInfo

Where to put it, from tryAdd

updateboolean<optional>
true

Upload to webgl now, pass false when batching

sourcePaddingnumber | Vector2<optional>
0

How many pixels padding around each frame in the source image

tryAdd(imageSize, frameSizeopt, paddingopt, sourcePaddingopt) → {TileInfo}

Find a spot for an image on this sheet without drawing it

Parameters:
NameTypeAttributesDefaultDescription
imageSizeVector2

Size of the source image in pixels

frameSizeVector2<optional>

Size of each frame, or the whole image if not passed

paddingnumber<optional>

How many pixels padding around each frame

sourcePaddingnumber | Vector2<optional>
0

How many pixels padding around each frame in the source image

Returns:

Tile for the packed image, or undefined if the sheet is full

Type: 
TileInfo

updateTexture()

Upload the canvas to webgl if it has changed since the last upload Only needed after batching, drawImage uploads automatically by default