Skip to content

1681-engine / postfx / PostFx

Class: PostFx ​

Defined in: src/postfx/PostFx.ts:52

Full-screen effects over a game: a chain of filters (vignette, bloom, a colour grade, CRT, pixelate…) laid over the picture in the order added, switched on and off one by one, and short effects that come and go — a flash, a shockwave, any uniform animated over time. One per engine is plenty; give it to the scenes that want it.

ts
const post = PostFx.forEngine(engine);
const vignette = post.add(new VignetteFilter({ strength: 0.4 }));
post.add(new BloomFilter({ threshold: 0.75 }));
post.flash({ color: 0xffffff, ms: 120 }); // a hit
post.shockwave(x, y); // screen pixels: an explosion
post.animate((v) => (vignette.strength = v), 0.4, 0.8, 300, 'Sine.InOut'); // a heartbeat

Constructors ​

Constructor ​

ts
new PostFx(
   target, 
   screen, 
   options?
): PostFx;

Defined in: src/postfx/PostFx.ts:62

Parameters ​

ParameterTypeDescription
targetContainer-
screenRectangleThe screen rectangle, live (the renderer's screen): what is filtered, and how screen points map to it.
optionsPostFxOptions-

Returns ​

PostFx

Properties ​

animator ​

ts
readonly animator: FxAnimator;

Defined in: src/postfx/PostFx.ts:53


target ​

ts
readonly target: Container;

Defined in: src/postfx/PostFx.ts:63

Accessors ​

color ​

Get Signature ​

ts
get color(): ColorAdjustFilter;

Defined in: src/postfx/PostFx.ts:155

The colour adjustment flash uses, made and put first in the chain the first time: brightness, saturation, a tint.

Returns ​

ColorAdjustFilter


filters ​

Get Signature ​

ts
get filters(): readonly Filter[];

Defined in: src/postfx/PostFx.ts:112

Every effect in the chain, in order.

Returns ​

readonly Filter[]

Methods ​

add() ​

ts
add<T>(filter, index?): T;

Defined in: src/postfx/PostFx.ts:85

Adds an effect at the end of the chain (or at index) and returns it.

Type Parameters ​

Type Parameter
T extends Filter

Parameters ​

ParameterType
filterT
indexnumber

Returns ​

T


animate() ​

ts
animate(
   set, 
   from, 
   to, 
   ms, 
   ease?, 
   done?
): void;

Defined in: src/postfx/PostFx.ts:117

Animates any number (a uniform, an effect's property) from from to to over ms.

Parameters ​

ParameterType
set(v) => void
fromnumber
tonumber
msnumber
ease?string | EaseFn
done?() => void

Returns ​

void


destroy() ​

ts
destroy(): void;

Defined in: src/postfx/PostFx.ts:165

Returns ​

void


flash() ​

ts
flash(options?): void;

Defined in: src/postfx/PostFx.ts:122

The whole picture washed towards a colour, fading out over ms. Skipped under reduced effects.

Parameters ​

ParameterType
optionsFlashOptions

Returns ​

void


isEnabled() ​

ts
isEnabled(filter): boolean;

Defined in: src/postfx/PostFx.ts:107

Parameters ​

ParameterType
filterFilter

Returns ​

boolean


remove() ​

ts
remove(filter): void;

Defined in: src/postfx/PostFx.ts:92

Takes an effect out (it is not destroyed: add it back later, or destroy it yourself).

Parameters ​

ParameterType
filterFilter

Returns ​

void


setEnabled() ​

ts
setEnabled(filter, on): void;

Defined in: src/postfx/PostFx.ts:100

Turns an effect on or off without taking it out of its place.

Parameters ​

ParameterType
filterFilter
onboolean

Returns ​

void


shockwave() ​

ts
shockwave(
   x, 
   y, 
   options?
): void;

Defined in: src/postfx/PostFx.ts:130

A ring of bent picture spreading from a screen point (screen pixels). Skipped under reduced effects.

Parameters ​

ParameterType
xnumber
ynumber
optionsShockwaveRun

Returns ​

void


update() ​

ts
update(ms): void;

Defined in: src/postfx/PostFx.ts:160

Steps the animations; forEngine calls it on every frame.

Parameters ​

ParameterType
msnumber

Returns ​

void


forEngine() ​

ts
static forEngine(engine, options?): PostFx;

Defined in: src/postfx/PostFx.ts:75

A PostFx over an engine's picture, stepped on its frames.

Parameters ​

ParameterType
engineEngine
optionsPostFxOptions

Returns ​

PostFx

Released under the MIT License.