Reference Source
public class | source

ParallaxSingleton

You can directly use an instance of this class. Parallax

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public

The layer class.

public

version: *

The version of the module.

Private Members
private

Weakmap to store info on instances used in this module.

private

An set of instances that use the parallax system.

private

The last position of the camera.

private

The logger module this module uses to log errors / logs

Method Summary

Public Methods
public

add(pInstance: Object, pConfig: Object, pX: number, pY: number, pMap: string)

Adds an instance to the parallax system.

public

handleOnRelocated(pInstance: Diob | MapObject, pChildren: MapObject[])

Handles the onRelocated event for instances.

public

remove(pInstance: Object)

Removes an instance to the parallax system.

public

update(pCameraX: number, pCameraY: number)

Updates the parallax system.

Private Methods
private

init(pInstance: Object, pConfig: Object, pX: number, pY: number, pMap: string)

Initializes this instance.

Public Constructors

public constructor() source

Public Members

public Layer: Layer source

The layer class.

public version: * source

The version of the module.

Private Members

private instanceWeakMap: WeakMap source

Weakmap to store info on instances used in this module.

private instances: Set source

An set of instances that use the parallax system.

private lastCamPos: Object source

The last position of the camera.

private logger: Object source

The logger module this module uses to log errors / logs

Public Methods

public add(pInstance: Object, pConfig: Object, pX: number, pY: number, pMap: string) source

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

Params:

NameTypeAttributeDescription
pInstance Object

The instance to add to the parallax system.

pConfig Object

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

pX number
  • optional

The x position this instance will start at.

pY number
  • optional

The y position this instance will start at.

pMap string
  • optional

The map this instance will start at.

The following is how the speed of the parallax multipliers are factored in.

(x | y) < 1 = faster behind the camera eg: (-> Player goes this way = Instance goes this way <-)
(x | y) > 1 faster against the camera eg: (-> Player goes this way = Instance goes this way ->)
(x | y) = 0 = static to the camera eg: (-> Player goes this way = Instance does nothing, and moves with the camera)
(x | y) = 1 = moves with the camera eg: (-> Player goes this way = Instance goes this way -> at position of camera)

public handleOnRelocated(pInstance: Diob | MapObject, pChildren: MapObject[]) source

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

Params:

NameTypeAttributeDescription
pInstance Diob | MapObject

The instance to handle the event for.

pChildren MapObject[]

An array of children belonging to the instance.

public remove(pInstance: Object) source

Removes an instance to the parallax system.

Params:

NameTypeAttributeDescription
pInstance Object

The instance to remove to the parallax system.

public update(pCameraX: number, pCameraY: number) source

Updates the parallax system.

Params:

NameTypeAttributeDescription
pCameraX number

The x position of the camera.

pCameraY number

The y position of the camera.

Private Methods

private init(pInstance: Object, pConfig: Object, pX: number, pY: number, pMap: string) source

Initializes this instance.

Params:

NameTypeAttributeDescription
pInstance Object

The instance to initialize.

pConfig Object

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

pX number

The x position this parallax will start at.

pY number

The y position this parallax will start at.

pMap string

The map this instance will start at.