Class ParallaxSingleton

The ParallaxSingleton class provides the core functionality for managing parallax effects. This class is typically used as a singleton instance exported as Parallax.

Example

import { Parallax } from 'parallax';

// The Parallax instance is already created and ready to use
Parallax.add(myInstance, config);
Parallax.update(cameraX, cameraY);

Constructors

Properties

version: string = "VERSION_REPLACE_ME"

The version of the module.

logger: any = ...

The logger module this module uses to log errors / logs

events: EventEmitter = ...

The event emitter.

Layer: typeof Layer = Layer

The layer class.

instances: Set<any> = ...

An set of instances that use the parallax system.

instanceWeakMap: WeakMap<any, ParallaxInstanceInfo> = ...

Weakmap to store info on instances used in this module.

lastCamPos: CameraPosition = ...

The last position of the camera.

cameraAnchor: CameraPosition = ...

The virtual position on the map where the layers look natural together.

anchorYSet: boolean = false

Whether the anchor y position is set.

anchorXSet: boolean = false

Whether the anchor x position is set.

Methods

  • Whether the last camera position is set.

    Returns boolean

    Whether the last camera position is set.

  • Sets the last camera position.

    Parameters

    • pX: number

      The last x position of the camera.

    • pY: number

      The last y position of the camera.

    Returns void

  • Sets the anchor position for the parallax system.

    Parameters

    • pCameraAnchor: CameraPosition

      The virtual position on the map where the layers look natural together.

    Returns void

  • Sets the anchor x position for the parallax system.

    Parameters

    • pXAnchor: null | number

      The x position to set the anchor to.

    Returns void

  • Sets the anchor y position for the parallax system.

    Parameters

    • pYAnchor: null | number

      The y position to set the anchor to.

    Returns void

  • Gets the anchor x position.

    Returns null | number

    The anchor x position.

  • Gets the anchor y position.

    Returns null | number

    The anchor y position.

  • Resets the anchor position.

    Returns void

  • Resets the anchor x position.

    Returns void

  • Resets the anchor y position.

    Returns void

  • Whether the anchor x position is set.

    Returns boolean

    Whether the anchor x position is set.

  • Whether the anchor y position is set.

    Returns boolean

    Whether the anchor y position is set.

  • Creates two clones of the instance to loop infinitely.

    Parameters

    • pInstance: any

      The instance to base the clones off of.

    Returns any[]

    An array of the two clones.

  • Enables infinite looping for the horizontal plane.

    Parameters

    • pInstance: any

      The instance to loop.

    Returns void

  • Enables infinite looping for the vertical plane.

    Parameters

    • pInstance: any

      The instance to loop.

    Returns void

  • Toggle infinite looping for both the horizontal and vertical planes.

    Parameters

    • pInstance: any

      The instance to loop.

    Returns void

  • Adds an instance to the parallax system. Call this first and then add your instance to the map.

    Parameters

    • pInstance: any

      The instance to add to the parallax system.

    • pConfig: ParallaxConfig

      The parallax info that tells this module how to control this instance.

    Returns void

  • Initializes this instance.

    Parameters

    • pInstance: any

      The instance to initialize.

    • pConfig: ParallaxConfig

      The parallax info that tells this module how to control this instance.

    Returns void

  • Removes an instance to the parallax system.

    Parameters

    • pInstance: any

      The instance to remove to the parallax system.

    Returns void

  • Updates the parallax system.

    Parameters

    • pCameraX: number = 0

      The x position of the camera.

    • pCameraY: number = 0

      The y position of the camera.

    Returns void

  • Updates the instance's position based on the camera's position.

    Parameters

    • pInstance: any

      The instance to update.

    • pCameraX: number

      The x position of the camera.

    • pCameraY: number

      The y position of the camera.

    • Optional pAnchor: CameraPosition

      The camera anchor position to use.

    Returns void

  • Handles the onRelocated event for instances. Moves their children in relativity to their position.

    Parameters

    • pInstance: any

      The instance to handle the event for.

    Returns void