Skip to content

1681-engine / index / CanvasTexture

Class: CanvasTexture ​

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

A canvas-backed texture with named frames; repaint the canvas, then refresh() to upload it. Made with a view, it is one rect of another texture's canvas on that texture's own source (TextureRegistry.addView): small pieces swapped every few frames then batch together, where a source each made Pixi rebuild its draw instructions at every swap.

Constructors ​

Constructor ​

ts
new CanvasTexture(
   key, 
   canvas, 
   view?
): CanvasTexture;

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

Parameters ​

ParameterType
keystring
canvasHTMLCanvasElement
view?{ frame: Rectangle; source: CanvasSource; }
view.frame?Rectangle
view.source?CanvasSource

Returns ​

CanvasTexture

Properties ​

canvas ​

ts
readonly canvas: HTMLCanvasElement;

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


frames ​

ts
readonly frames: Map<string, Texture<TextureSource<any>>>;

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


key ​

ts
readonly key: string;

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


source ​

ts
readonly source: CanvasSource;

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


whole ​

ts
readonly whole: Texture;

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

Accessors ​

context ​

Get Signature ​

ts
get context(): CanvasRenderingContext2D;

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

Returns ​

CanvasRenderingContext2D


height ​

Get Signature ​

ts
get height(): number;

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

Returns ​

number


width ​

Get Signature ​

ts
get width(): number;

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

Returns ​

number

Methods ​

add() ​

ts
add(
   name, 
   _source, 
   x, 
   y, 
   w, 
   h
): void;

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

Adds a frame cut from the canvas (_source kept for the old call shape).

Parameters ​

ParameterType
namestring
_sourcenumber
xnumber
ynumber
wnumber
hnumber

Returns ​

void


addPacked() ​

ts
addPacked(frame, page?): void;

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

Adds a packed frame cut from page (this texture's canvas by default): trimmed frames keep their untrimmed size (orig) so they line up when drawn, and frames the packer turned are turned back (Pixi's rotate: 2).

Parameters ​

ParameterType
framePackedFrame
pageCanvasTexture

Returns ​

void


adopt() ​

ts
adopt(name, from): void;

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

Registers under this texture a frame that lives on another one (an atlas page after the first), so the frame is found by this texture's key. A texture of its own over the other page's source: each side frees its own.

Parameters ​

ParameterType
namestring
fromCanvasTexture

Returns ​

void


destroy() ​

ts
destroy(): void;

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

Returns ​

void


refresh() ​

ts
refresh(): void;

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

Returns ​

void

Released under the MIT License.