Skip to content

1681-engine / index / Parallax

Class: Parallax ​

Defined in: src/parallax/Parallax.ts:27

Layers of scenery behind (or before) the world, each scrolling at its own share of the camera's speed. Add view to the world layer — a scene's root — and call update(camera, dtMs) once a frame after the camera moved, so the layers sit where this frame's view is:

ts
const sky = new Parallax();
sky.add({ texture: clouds, factorX: 0.1, repeatX: true, speedX: -6 });
sky.add({ display: hills, factorX: 0.5, factorY: 1 });
this.root.addChild(sky.view);
// each frame
sky.update(stage.cameras.main, dt * 1000);

Constructors ​

Constructor ​

ts
new Parallax(options?): Parallax;

Defined in: src/parallax/Parallax.ts:31

Parameters ​

ParameterType
optionsParallaxOptions

Returns ​

Parallax

Properties ​

view ​

ts
readonly view: Container<ContainerChild>;

Defined in: src/parallax/Parallax.ts:28

Accessors ​

layers ​

Get Signature ​

ts
get layers(): readonly ParallaxLayer[];

Defined in: src/parallax/Parallax.ts:35

Returns ​

readonly ParallaxLayer[]

Methods ​

add() ​

ts
add(layer): ParallaxLayer;

Defined in: src/parallax/Parallax.ts:40

Adds a layer (built here from options, or one made before); later layers draw in front unless a depth says.

Parameters ​

ParameterType
layer| ParallaxLayerOptions | ParallaxLayer

Returns ​

ParallaxLayer


destroy() ​

ts
destroy(): void;

Defined in: src/parallax/Parallax.ts:60

Returns ​

void


remove() ​

ts
remove(layer): void;

Defined in: src/parallax/Parallax.ts:49

Takes a layer out and destroys it.

Parameters ​

ParameterType
layerParallaxLayer

Returns ​

void


update() ​

ts
update(camera, dtMs): void;

Defined in: src/parallax/Parallax.ts:56

Parameters ​

ParameterType
cameraParallaxCamera
dtMsnumber

Returns ​

void

Released under the MIT License.