Skip to content

1681-engine / pixel / PixelLayer

Class: PixelLayer ​

Defined in: src/pixel/PixelLayer.ts:109

Dither, 1681 Engine's pixel-art module: import { … } from '1681-engine/pixel'.

Everything here works on the world's own pixel grid: rects batched into one texture, shapes shaded by hue-shifted ramps and faded by ordered dither, dithered lighting, bodies that evaporate into their own pixels. Start the engine with pixelPerfect: true so textures stay sharp and the camera lands on whole pixels.

Extends ​

Constructors ​

Constructor ​

ts
new PixelLayer(): PixelLayer;

Defined in: src/pixel/PixelLayer.ts:126

Returns ​

PixelLayer

Overrides ​

Graphics.constructor

Properties ​

active ​

ts
readonly active: boolean;

Defined in: src/core/gameObject.ts:42

False once destroyed.

Inherited from ​

Graphics.active


depth ​

ts
depth: number;

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

The draw order in the world layer (zIndex): bigger is in front.

Inherited from ​

Graphics.depth


flipX ​

ts
flipX: boolean;

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

Inherited from ​

Graphics.flipX


flipY ​

ts
flipY: boolean;

Defined in: src/core/gameObject.ts:49

Inherited from ​

Graphics.flipY


scaleX ​

ts
scaleX: number;

Defined in: src/core/gameObject.ts:46

Scale without the flip: stays positive on a mirrored sprite.

Inherited from ​

Graphics.scaleX


scaleY ​

ts
scaleY: number;

Defined in: src/core/gameObject.ts:47

Inherited from ​

Graphics.scaleY


scene ​

ts
scene: Stage;

Defined in: src/core/gameObject.ts:40

Inherited from ​

Graphics.scene

Methods ​

beginPath() ​

ts
beginPath(): this;

Defined in: src/core/Graphics.ts:84

Returns ​

this

Inherited from ​

Graphics.beginPath


capacity() ​

ts
capacity(): object;

Defined in: src/pixel/PixelLayer.ts:325

The buffer's size (tests read it).

Returns ​

object

h ​
ts
h: number;
w ​
ts
w: number;

clear() ​

ts
clear(): this;

Defined in: src/pixel/PixelLayer.ts:186

Returns ​

this

Overrides ​

Graphics.clear


clearTint() ​

ts
clearTint(): this;

Defined in: src/core/gameObject.ts:64

Returns ​

this

Inherited from ​

Graphics.clearTint


closePath() ​

ts
closePath(): this;

Defined in: src/core/Graphics.ts:99

Returns ​

this

Inherited from ​

Graphics.closePath


commit() ​

ts
commit(): void;

Defined in: src/pixel/PixelLayer.ts:177

Lays the staged runs, as opaque rects, after everything drawn so far.

Returns ​

void


destroy() ​

ts
destroy(): void;

Defined in: src/pixel/PixelLayer.ts:359

Removes all internal references and listeners as well as removes children from the display list. Do not use a Container after calling destroy.

Returns ​

void

Example ​

ts
container.destroy();
container.destroy(true);
container.destroy({ children: true });
container.destroy({ children: true, texture: true, textureSource: true });

Overrides ​

Graphics.destroy


fillCircle() ​

ts
fillCircle(
   x, 
   y, 
   r
): this;

Defined in: src/core/Graphics.ts:53

Parameters ​

ParameterType
xnumber
ynumber
rnumber

Returns ​

this

Inherited from ​

Graphics.fillCircle


fillEllipse() ​

ts
fillEllipse(
   x, 
   y, 
   w, 
   h
): this;

Defined in: src/core/Graphics.ts:43

Parameters ​

ParameterType
xnumber
ynumber
wnumber
hnumber

Returns ​

this

Inherited from ​

Graphics.fillEllipse


fillPath() ​

ts
fillPath(): this;

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

Returns ​

this

Inherited from ​

Graphics.fillPath


fillPoints() ​

ts
fillPoints(points, _closeShape?): this;

Defined in: src/core/Graphics.ts:68

Parameters ​

ParameterTypeDefault value
pointsVec2[]undefined
_closeShapebooleantrue

Returns ​

this

Inherited from ​

Graphics.fillPoints


fillRect() ​

ts
fillRect(
   x, 
   y, 
   w, 
   h
): this;

Defined in: src/pixel/PixelLayer.ts:152

Parameters ​

ParameterType
xnumber
ynumber
wnumber
hnumber

Returns ​

this

Overrides ​

Graphics.fillRect


fillStyle() ​

ts
fillStyle(color, alpha?): this;

Defined in: src/pixel/PixelLayer.ts:146

Parameters ​

ParameterTypeDefault value
colornumberundefined
alphanumber1

Returns ​

this

Overrides ​

Graphics.fillStyle


hideMirror() ​

ts
hideMirror(): void;

Defined in: src/pixel/PixelLayer.ts:305

Shows nothing and lets go of the texture a mirror showed.

Returns ​

void


lineBetween() ​

ts
lineBetween(
   x1, 
   y1, 
   x2, 
   y2
): this;

Defined in: src/core/Graphics.ts:63

Parameters ​

ParameterType
x1number
y1number
x2number
y2number

Returns ​

this

Inherited from ​

Graphics.lineBetween


lineStyle() ​

ts
lineStyle(
   width, 
   color, 
   alpha?
): this;

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

Parameters ​

ParameterTypeDefault value
widthnumberundefined
colornumberundefined
alphanumber1

Returns ​

this

Inherited from ​

Graphics.lineStyle


lineTo() ​

ts
lineTo(x, y): this;

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

Parameters ​

ParameterType
xnumber
ynumber

Returns ​

this

Inherited from ​

Graphics.lineTo


mirror() ​

ts
mirror(other): void;

Defined in: src/pixel/PixelLayer.ts:289

Shows other's last frame instead of painting one: its texture, placed where it placed it. A frame shared by several bodies (the same aura on two bodies) is painted once and shown by each of their layers.

Parameters ​

ParameterType
otherPixelLayer

Returns ​

void


moveTo() ​

ts
moveTo(x, y): this;

Defined in: src/core/Graphics.ts:89

Parameters ​

ParameterType
xnumber
ynumber

Returns ​

this

Inherited from ​

Graphics.moveTo


pixelAt() ​

ts
pixelAt(x, y): [number, number, number, number];

Defined in: src/pixel/PixelLayer.ts:311

The premultiplied [r, g, b, a] last presented at layer pixel (x, y); zeros where nothing was (tests read it).

Parameters ​

ParameterType
xnumber
ynumber

Returns ​

[number, number, number, number]


present() ​

ts
present(): void;

Defined in: src/pixel/PixelLayer.ts:199

Writes this frame's rects into the texture and shows it; call once the frame is painted.

Returns ​

void


reach() ​

ts
reach(): number;

Defined in: src/pixel/PixelLayer.ts:193

How far the last frame reached from the layer's origin, in world pixels (0 when nothing showed).

Returns ​

number


rect() ​

ts
rect(
   x, 
   y, 
   w, 
   h, 
   color, 
   alpha?
): void;

Defined in: src/pixel/PixelLayer.ts:162

fillStyle + fillRect on whole pixels in one call, leaving the fill style alone (a hot loop's way in).

Parameters ​

ParameterTypeDefault value
xnumberundefined
ynumberundefined
wnumberundefined
hnumberundefined
colornumberundefined
alphanumber1

Returns ​

void


setAlpha() ​

ts
setAlpha(a?): this;

Defined in: src/core/gameObject.ts:55

Parameters ​

ParameterType
a?number

Returns ​

this

Inherited from ​

Graphics.setAlpha


setAngle() ​

ts
setAngle(a?): this;

Defined in: src/core/gameObject.ts:59

Parameters ​

ParameterType
a?number

Returns ​

this

Inherited from ​

Graphics.setAngle


setBlendMode() ​

ts
setBlendMode(mode): this;

Defined in: src/core/gameObject.ts:60

Parameters ​

ParameterType
modeBLEND_MODES

Returns ​

this

Inherited from ​

Graphics.setBlendMode


setDepth() ​

ts
setDepth(d): this;

Defined in: src/core/gameObject.ts:54

Parameters ​

ParameterType
dnumber

Returns ​

this

Inherited from ​

Graphics.setDepth


setFlip() ​

ts
setFlip(x, y): this;

Defined in: src/core/gameObject.ts:53

Parameters ​

ParameterType
xboolean
yboolean

Returns ​

this

Inherited from ​

Graphics.setFlip


setFlipX() ​

ts
setFlipX(v): this;

Defined in: src/core/gameObject.ts:51

Parameters ​

ParameterType
vboolean

Returns ​

this

Inherited from ​

Graphics.setFlipX


setFlipY() ​

ts
setFlipY(v): this;

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

Parameters ​

ParameterType
vboolean

Returns ​

this

Inherited from ​

Graphics.setFlipY


setPosition() ​

ts
setPosition(x?, y?): this;

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

Parameters ​

ParameterType
x?number
y?number

Returns ​

this

Inherited from ​

Graphics.setPosition


setRotation() ​

ts
setRotation(r?): this;

Defined in: src/core/gameObject.ts:58

Parameters ​

ParameterType
r?number

Returns ​

this

Inherited from ​

Graphics.setRotation


setScale() ​

ts
setScale(x, y?): this;

Defined in: src/core/gameObject.ts:50

Parameters ​

ParameterType
xnumber
y?number

Returns ​

this

Inherited from ​

Graphics.setScale


setScrollFactor() ​

ts
setScrollFactor(f): this;

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

0 pins the object to the screen instead of the world.

Parameters ​

ParameterType
fnumber

Returns ​

this

Inherited from ​

Graphics.setScrollFactor


setTint() ​

ts
setTint(color?): this;

Defined in: src/core/gameObject.ts:61

Parameters ​

ParameterType
color?number

Returns ​

this

Inherited from ​

Graphics.setTint


setTintFill() ​

ts
setTintFill(color): this;

Defined in: src/core/gameObject.ts:63

Paints every opaque pixel in one solid colour (hit flash, silhouettes).

Parameters ​

ParameterType
colornumber

Returns ​

this

Inherited from ​

Graphics.setTintFill


setVisible() ​

ts
setVisible(v): this;

Defined in: src/core/gameObject.ts:56

Parameters ​

ParameterType
vboolean

Returns ​

this

Inherited from ​

Graphics.setVisible


slice() ​

ts
slice(
   x, 
   y, 
   r, 
   start, 
   end, 
   anticlockwise?
): this;

Defined in: src/core/Graphics.ts:79

A pie slice from the centre, for cone telegraphs.

Parameters ​

ParameterTypeDefault value
xnumberundefined
ynumberundefined
rnumberundefined
startnumberundefined
endnumberundefined
anticlockwisebooleanfalse

Returns ​

this

Inherited from ​

Graphics.slice


stage() ​

ts
stage(
   x, 
   y, 
   w, 
   color
): void;

Defined in: src/pixel/PixelLayer.ts:172

A solid run of w whole pixels at (x, y) in color, held until commit lays every staged run in the order given (the later winning where they cross), after whatever was drawn before the commit. What pixelTone's batch writes instead of filing each pixel in a map and sorting it into rects.

Parameters ​

ParameterType
xnumber
ynumber
wnumber
colornumber

Returns ​

void


strokeCircle() ​

ts
strokeCircle(
   x, 
   y, 
   r
): this;

Defined in: src/core/Graphics.ts:58

Parameters ​

ParameterType
xnumber
ynumber
rnumber

Returns ​

this

Inherited from ​

Graphics.strokeCircle


strokeEllipse() ​

ts
strokeEllipse(
   x, 
   y, 
   w, 
   h
): this;

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

Parameters ​

ParameterType
xnumber
ynumber
wnumber
hnumber

Returns ​

this

Inherited from ​

Graphics.strokeEllipse


strokePath() ​

ts
strokePath(): this;

Defined in: src/core/Graphics.ts:109

Returns ​

this

Inherited from ​

Graphics.strokePath


strokePoints() ​

ts
strokePoints(points, closeShape?): this;

Defined in: src/core/Graphics.ts:73

Parameters ​

ParameterTypeDefault value
pointsVec2[]undefined
closeShapebooleanfalse

Returns ​

this

Inherited from ​

Graphics.strokePoints


drainPool() ​

ts
static drainPool(): void;

Defined in: src/pixel/PixelLayer.ts:140

Lets every pooled buffer go (the world changed map): the next map's effects start a pool of their own.

Returns ​

void


stats() ​

ts
static stats(): object;

Defined in: src/pixel/PixelLayer.ts:133

Textures made, spent buffers waiting in the pool and their bytes (the leak tools read it).

Returns ​

object

made ​
ts
made: number;
pooled ​
ts
pooled: number;
pooledBytes ​
ts
pooledBytes: number;

Released under the MIT License.