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:
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 ​
new Parallax(options?): Parallax;Defined in: src/parallax/Parallax.ts:31
Parameters ​
| Parameter | Type |
|---|---|
options | ParallaxOptions |
Returns ​
Parallax
Properties ​
view ​
readonly view: Container<ContainerChild>;Defined in: src/parallax/Parallax.ts:28
Accessors ​
layers ​
Get Signature ​
get layers(): readonly ParallaxLayer[];Defined in: src/parallax/Parallax.ts:35
Returns ​
readonly ParallaxLayer[]
Methods ​
add() ​
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 ​
| Parameter | Type |
|---|---|
layer | | ParallaxLayerOptions | ParallaxLayer |
Returns ​
destroy() ​
destroy(): void;Defined in: src/parallax/Parallax.ts:60
Returns ​
void
remove() ​
remove(layer): void;Defined in: src/parallax/Parallax.ts:49
Takes a layer out and destroys it.
Parameters ​
| Parameter | Type |
|---|---|
layer | ParallaxLayer |
Returns ​
void
update() ​
update(camera, dtMs): void;Defined in: src/parallax/Parallax.ts:56
Parameters ​
| Parameter | Type |
|---|---|
camera | ParallaxCamera |
dtMs | number |
Returns ​
void