LittleJS 1.28.0

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(size)textureSheet.js:48

Create a texture sheet, called automatically by loadSprite

size number optional

Width and height of the sheet in pixels

Members

Methods

Members

canvas : OffscreenCanvastextureSheet.js:61

Canvas holding the packed images

context : OffscreenCanvasRenderingContext2DtextureSheet.js:59

2d context for the canvas

Where the next image will be packed

glDirty : booleantextureSheet.js:69

Has the canvas changed since the last webgl upload?

rowHeight : numbertextureSheet.js:67

Height of the row being packed

size : numbertextureSheet.js:57

Width and height of the sheet in pixels

The texture info for this sheet

Methods

drawImage(image, tileInfo, update, sourcePadding)textureSheet.js:145

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

image HTMLImageElement|HTMLCanvasElement|OffscreenCanvas|ImageBitmap

Source image to copy from

tileInfo TileInfo

Where to put it, from tryAdd

update boolean optional, default true

Upload to webgl now, pass false when batching

sourcePadding number|Vector2 optional, default 0

How many pixels padding around each frame in the source image

tryAdd(imageSize, frameSize, padding, sourcePadding) → TileInfo|undefinedtextureSheet.js:85

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

imageSize Vector2

Size of the source image in pixels

frameSize Vector2 optional

Size of each frame, or the whole image less its source padding if not passed

padding number optional

How many pixels padding around each frame

sourcePadding number|Vector2 optional, default 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

updateTexture()textureSheet.js:182

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