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 ​
new PixelLayer(): PixelLayer;Defined in: src/pixel/PixelLayer.ts:126
Returns ​
PixelLayer
Overrides ​
Properties ​
active ​
readonly active: boolean;Defined in: src/core/gameObject.ts:42
False once destroyed.
Inherited from ​
depth ​
depth: number;Defined in: src/core/gameObject.ts:44
The draw order in the world layer (zIndex): bigger is in front.
Inherited from ​
flipX ​
flipX: boolean;Defined in: src/core/gameObject.ts:48
Inherited from ​
flipY ​
flipY: boolean;Defined in: src/core/gameObject.ts:49
Inherited from ​
scaleX ​
scaleX: number;Defined in: src/core/gameObject.ts:46
Scale without the flip: stays positive on a mirrored sprite.
Inherited from ​
scaleY ​
scaleY: number;Defined in: src/core/gameObject.ts:47
Inherited from ​
scene ​
scene: Stage;Defined in: src/core/gameObject.ts:40
Inherited from ​
Methods ​
beginPath() ​
beginPath(): this;Defined in: src/core/Graphics.ts:84
Returns ​
this
Inherited from ​
capacity() ​
capacity(): object;Defined in: src/pixel/PixelLayer.ts:325
The buffer's size (tests read it).
Returns ​
object
h ​
h: number;w ​
w: number;clear() ​
clear(): this;Defined in: src/pixel/PixelLayer.ts:186
Returns ​
this
Overrides ​
clearTint() ​
clearTint(): this;Defined in: src/core/gameObject.ts:64
Returns ​
this
Inherited from ​
closePath() ​
closePath(): this;Defined in: src/core/Graphics.ts:99
Returns ​
this
Inherited from ​
commit() ​
commit(): void;Defined in: src/pixel/PixelLayer.ts:177
Lays the staged runs, as opaque rects, after everything drawn so far.
Returns ​
void
destroy() ​
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 ​
container.destroy();
container.destroy(true);
container.destroy({ children: true });
container.destroy({ children: true, texture: true, textureSource: true });Overrides ​
fillCircle() ​
fillCircle(
x,
y,
r
): this;Defined in: src/core/Graphics.ts:53
Parameters ​
| Parameter | Type |
|---|---|
x | number |
y | number |
r | number |
Returns ​
this
Inherited from ​
fillEllipse() ​
fillEllipse(
x,
y,
w,
h
): this;Defined in: src/core/Graphics.ts:43
Parameters ​
| Parameter | Type |
|---|---|
x | number |
y | number |
w | number |
h | number |
Returns ​
this
Inherited from ​
fillPath() ​
fillPath(): this;Defined in: src/core/Graphics.ts:104
Returns ​
this
Inherited from ​
fillPoints() ​
fillPoints(points, _closeShape?): this;Defined in: src/core/Graphics.ts:68
Parameters ​
| Parameter | Type | Default value |
|---|---|---|
points | Vec2[] | undefined |
_closeShape | boolean | true |
Returns ​
this
Inherited from ​
fillRect() ​
fillRect(
x,
y,
w,
h
): this;Defined in: src/pixel/PixelLayer.ts:152
Parameters ​
| Parameter | Type |
|---|---|
x | number |
y | number |
w | number |
h | number |
Returns ​
this
Overrides ​
fillStyle() ​
fillStyle(color, alpha?): this;Defined in: src/pixel/PixelLayer.ts:146
Parameters ​
| Parameter | Type | Default value |
|---|---|---|
color | number | undefined |
alpha | number | 1 |
Returns ​
this
Overrides ​
hideMirror() ​
hideMirror(): void;Defined in: src/pixel/PixelLayer.ts:305
Shows nothing and lets go of the texture a mirror showed.
Returns ​
void
lineBetween() ​
lineBetween(
x1,
y1,
x2,
y2
): this;Defined in: src/core/Graphics.ts:63
Parameters ​
| Parameter | Type |
|---|---|
x1 | number |
y1 | number |
x2 | number |
y2 | number |
Returns ​
this
Inherited from ​
lineStyle() ​
lineStyle(
width,
color,
alpha?
): this;Defined in: src/core/Graphics.ts:28
Parameters ​
| Parameter | Type | Default value |
|---|---|---|
width | number | undefined |
color | number | undefined |
alpha | number | 1 |
Returns ​
this
Inherited from ​
lineTo() ​
lineTo(x, y): this;Defined in: src/core/Graphics.ts:94
Parameters ​
| Parameter | Type |
|---|---|
x | number |
y | number |
Returns ​
this
Inherited from ​
mirror() ​
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 ​
| Parameter | Type |
|---|---|
other | PixelLayer |
Returns ​
void
moveTo() ​
moveTo(x, y): this;Defined in: src/core/Graphics.ts:89
Parameters ​
| Parameter | Type |
|---|---|
x | number |
y | number |
Returns ​
this
Inherited from ​
pixelAt() ​
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 ​
| Parameter | Type |
|---|---|
x | number |
y | number |
Returns ​
[number, number, number, number]
present() ​
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() ​
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() ​
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 ​
| Parameter | Type | Default value |
|---|---|---|
x | number | undefined |
y | number | undefined |
w | number | undefined |
h | number | undefined |
color | number | undefined |
alpha | number | 1 |
Returns ​
void
setAlpha() ​
setAlpha(a?): this;Defined in: src/core/gameObject.ts:55
Parameters ​
| Parameter | Type |
|---|---|
a? | number |
Returns ​
this
Inherited from ​
setAngle() ​
setAngle(a?): this;Defined in: src/core/gameObject.ts:59
Parameters ​
| Parameter | Type |
|---|---|
a? | number |
Returns ​
this
Inherited from ​
setBlendMode() ​
setBlendMode(mode): this;Defined in: src/core/gameObject.ts:60
Parameters ​
| Parameter | Type |
|---|---|
mode | BLEND_MODES |
Returns ​
this
Inherited from ​
setDepth() ​
setDepth(d): this;Defined in: src/core/gameObject.ts:54
Parameters ​
| Parameter | Type |
|---|---|
d | number |
Returns ​
this
Inherited from ​
setFlip() ​
setFlip(x, y): this;Defined in: src/core/gameObject.ts:53
Parameters ​
| Parameter | Type |
|---|---|
x | boolean |
y | boolean |
Returns ​
this
Inherited from ​
setFlipX() ​
setFlipX(v): this;Defined in: src/core/gameObject.ts:51
Parameters ​
| Parameter | Type |
|---|---|
v | boolean |
Returns ​
this
Inherited from ​
setFlipY() ​
setFlipY(v): this;Defined in: src/core/gameObject.ts:52
Parameters ​
| Parameter | Type |
|---|---|
v | boolean |
Returns ​
this
Inherited from ​
setPosition() ​
setPosition(x?, y?): this;Defined in: src/core/gameObject.ts:57
Parameters ​
| Parameter | Type |
|---|---|
x? | number |
y? | number |
Returns ​
this
Inherited from ​
setRotation() ​
setRotation(r?): this;Defined in: src/core/gameObject.ts:58
Parameters ​
| Parameter | Type |
|---|---|
r? | number |
Returns ​
this
Inherited from ​
setScale() ​
setScale(x, y?): this;Defined in: src/core/gameObject.ts:50
Parameters ​
| Parameter | Type |
|---|---|
x | number |
y? | number |
Returns ​
this
Inherited from ​
setScrollFactor() ​
setScrollFactor(f): this;Defined in: src/core/gameObject.ts:66
0 pins the object to the screen instead of the world.
Parameters ​
| Parameter | Type |
|---|---|
f | number |
Returns ​
this
Inherited from ​
setTint() ​
setTint(color?): this;Defined in: src/core/gameObject.ts:61
Parameters ​
| Parameter | Type |
|---|---|
color? | number |
Returns ​
this
Inherited from ​
setTintFill() ​
setTintFill(color): this;Defined in: src/core/gameObject.ts:63
Paints every opaque pixel in one solid colour (hit flash, silhouettes).
Parameters ​
| Parameter | Type |
|---|---|
color | number |
Returns ​
this
Inherited from ​
setVisible() ​
setVisible(v): this;Defined in: src/core/gameObject.ts:56
Parameters ​
| Parameter | Type |
|---|---|
v | boolean |
Returns ​
this
Inherited from ​
slice() ​
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 ​
| Parameter | Type | Default value |
|---|---|---|
x | number | undefined |
y | number | undefined |
r | number | undefined |
start | number | undefined |
end | number | undefined |
anticlockwise | boolean | false |
Returns ​
this
Inherited from ​
stage() ​
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 ​
| Parameter | Type |
|---|---|
x | number |
y | number |
w | number |
color | number |
Returns ​
void
strokeCircle() ​
strokeCircle(
x,
y,
r
): this;Defined in: src/core/Graphics.ts:58
Parameters ​
| Parameter | Type |
|---|---|
x | number |
y | number |
r | number |
Returns ​
this
Inherited from ​
strokeEllipse() ​
strokeEllipse(
x,
y,
w,
h
): this;Defined in: src/core/Graphics.ts:48
Parameters ​
| Parameter | Type |
|---|---|
x | number |
y | number |
w | number |
h | number |
Returns ​
this
Inherited from ​
strokePath() ​
strokePath(): this;Defined in: src/core/Graphics.ts:109
Returns ​
this
Inherited from ​
strokePoints() ​
strokePoints(points, closeShape?): this;Defined in: src/core/Graphics.ts:73
Parameters ​
| Parameter | Type | Default value |
|---|---|---|
points | Vec2[] | undefined |
closeShape | boolean | false |
Returns ​
this
Inherited from ​
drainPool() ​
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() ​
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 ​
made: number;pooled ​
pooled: number;pooledBytes ​
pooledBytes: number;