Skip to content

1681-engine / index / TextureRegistry

Class: TextureRegistry ​

Defined in: src/core/TextureRegistry.ts:104

Every texture of the world by key: the sprite atlas and per-player repainted sheets.

Constructors ​

Constructor ​

ts
new TextureRegistry(): TextureRegistry;

Returns ​

TextureRegistry

Methods ​

addAtlas() ​

ts
addAtlas(key, pages): CanvasTexture;

Defined in: src/core/TextureRegistry.ts:181

A packed atlas (TexturePacker JSON, AssetLoader.atlas): the first page under key, the others as key~1, key~2… like AtlasBuilder's pages, and every frame of every page found under key by its name.

Parameters ​

ParameterType
keystring
pagesreadonly object[]

Returns ​

CanvasTexture


addCanvas() ​

ts
addCanvas(key, canvas): CanvasTexture;

Defined in: src/core/TextureRegistry.ts:159

Parameters ​

ParameterType
keystring
canvasHTMLCanvasElement

Returns ​

CanvasTexture


addSpriteSheet() ​

ts
addSpriteSheet(
   key, 
   canvas, 
   size
): CanvasTexture;

Defined in: src/core/TextureRegistry.ts:167

A canvas cut into equal frames named 0, 1, 2... left to right, then row by row.

Parameters ​

ParameterType
keystring
canvasHTMLCanvasElement
size{ frameHeight: number; frameWidth: number; }
size.frameHeightnumber
size.frameWidthnumber

Returns ​

CanvasTexture


addView() ​

ts
addView(
   key, 
   page, 
   x, 
   y, 
   w, 
   h
): CanvasTexture | null;

Defined in: src/core/TextureRegistry.ts:202

Registers key as the rect (x, y, w, h) of the texture page, on the page's source: shown by setTexture(key) like any texture, and batched with every other view of that page. Null when the page is not registered.

Parameters ​

ParameterType
keystring
pagestring
xnumber
ynumber
wnumber
hnumber

Returns ​

CanvasTexture | null


createCanvas() ​

ts
createCanvas(
   key, 
   width, 
   height
): CanvasTexture;

Defined in: src/core/TextureRegistry.ts:211

Parameters ​

ParameterType
keystring
widthnumber
heightnumber

Returns ​

CanvasTexture


exists() ​

ts
exists(key): boolean;

Defined in: src/core/TextureRegistry.ts:155

Parameters ​

ParameterType
keystring

Returns ​

boolean


get() ​

ts
get(key, frame?): Texture;

Defined in: src/core/TextureRegistry.ts:224

Parameters ​

ParameterType
keystring
frame?string | number

Returns ​

Texture


isLive() ​

ts
isLive(key): boolean;

Defined in: src/core/TextureRegistry.ts:115

Parameters ​

ParameterType
keystring

Returns ​

boolean


markLive() ​

ts
markLive(key): void;

Defined in: src/core/TextureRegistry.ts:111

Parameters ​

ParameterType
keystring

Returns ​

void


remove() ​

ts
remove(key): void;

Defined in: src/core/TextureRegistry.ts:218

Parameters ​

ParameterType
keystring

Returns ​

void


snapshot() ​

ts
snapshot(key, frame?): string;

Defined in: src/core/TextureRegistry.ts:120

A new texture holding frame frame of key as it is painted right now; returns its key (one frame, '0').

Parameters ​

ParameterType
keystring
frame?string | number

Returns ​

string


snapshotInto() ​

ts
snapshotInto(
   key, 
   frame, 
   into
): void;

Defined in: src/core/TextureRegistry.ts:137

snapshot into a texture kept for reuse (into): its canvas is repainted in place and uploaded again, and only made anew when the frame's size changes. Frame '0' is the copy.

Parameters ​

ParameterType
keystring
framestring | number | undefined
intostring

Returns ​

void

Released under the MIT License.