Reference Source
private class | source

LensComponent

You can directly use an instance of this class. Lens

TODO:

  • Create test project

Static Member Summary

Static Private Members
private static

An array of axis.

private static

The default ease.

private static

The default pan duration.

private static

The default tile size of the Vylocity Game Engine.

private static

The max amount of delta time between ticks.

private static

The max display an instance can be displayed at.

private static

An array of valid ease names.

Constructor Summary

Private Constructor
private

Member Summary

Public Members
public

The camera that lens controls.

public

version: *

The version of the module.

Private Members
private

Whether the camera is attached to something and will follow it.

private

If this camera is using custom settings currently.

private

The current instance this camera is following.

private

Whether the camera has been created and is ready for use or not.

private

Weakmap to track data belonging to instances used in this module.

private

The logger module this module uses to log errors / logs.

private

Whether the mapview has been initialized.

private

The old position that the camera was following in the last tick.

private

The settings this camera uses to operate.

private

A callback to be called when the camera is updated.

Method Summary

Public Methods
public

attach(pInstance: Object, pSettings: Object, pUpdateFunc: Function)

Attaches the camera to the passed instance.

public

Stops spectating.

public

detach()

Detaches the camera.

public

Check if the camera is currently moving.

public

Check if the camera is currently panning.

public

Check if the camera is currently shaking.

public

Check if the camera is currently spectating.

public

Check if the camera is currently zooming.

public

pan(pSettings: Object)

Pans the camera from one view to another view.

public

setSettings(pSettings: Object)

Sets the camera to operate using these user defined settings.

public

shake(pIntensity: number, pDuration: number, pRotational: boolean, pCallback: Function)

Shakes the camera with the passed settings.

public

spectate(pSettings: Object)

Spectates another instance with the camera using the passed settings.

public

zoom(pDestinationLevel: Object, pDuration: number, pEase: Object, pCallback: Function)

Zooms the camera in via the passed in arguments.

Private Methods
private

follow(pMethod: string, pElapsedMS: number)

Method to follow the target of the camera.

private

followLogic(pAxis: string, pPosition: Object, pMethod: string, pElapsedMS: number)

The logic for following instances via the camera.

private

Returns the true center position by using the x and y position and adding half of the icon's width / height. If no icon is found, we instead use the half of the default tileSize.

private

Builds and initiates the camera and assigns some presets to it

private

Event handler for when the second part of the pan completes.

private

Event handler for when the first part of the pan completes.

private
private
private

reset(pMethod: string)

Resets the camera based on the method passed.

private

shakeUpdate(pElapsedMS: number)

The method to update shaking when it is active.

private

update(pElapsedMS: number)

Update handler that is called each tick to update the camera's state

private

zoomUpdate(pElapsedMS: number)

The method to update the zoom when it is active.

Static Private Members

private static AXIS: Array source

An array of axis.

private static DEFAULT_EASE: string source

The default ease.

private static DEFAULT_PAN_DURATION: number source

The default pan duration. Used as default.

private static DEFAULT_TILE_SIZE: number source

The default tile size of the Vylocity Game Engine.

private static MAX_DELTA_TIME: number source

The max amount of delta time between ticks. If this limit is passed, it will be clamped to this value.

private static MAX_DISPLAY: number source

The max display an instance can be displayed at.

private static validEase: Array source

An array of valid ease names.

Private Constructors

private constructor() source

Public Members

public camera: Object source

The camera that lens controls.

public version: * source

The version of the module.

Private Members

private attached: boolean source

Whether the camera is attached to something and will follow it.

private custom: boolean source

If this camera is using custom settings currently.

private following: Object source

The current instance this camera is following.

private initialized: boolean source

Whether the camera has been created and is ready for use or not.

private instanceWeakMap: WeakMap source

Weakmap to track data belonging to instances used in this module.

private logger: Object source

The logger module this module uses to log errors / logs.

private mapViewInitialized: boolean source

Whether the mapview has been initialized.

private oldFollowingPos: Object source

The old position that the camera was following in the last tick.

private settings: Object source

The settings this camera uses to operate.

private updateWithCamera(-: number, -: number): Function | undefined source

A callback to be called when the camera is updated.

Public Methods

public attach(pInstance: Object, pSettings: Object, pUpdateFunc: Function) source

Attaches the camera to the passed instance.

Params:

NameTypeAttributeDescription
pInstance Object

The instance to attach the camera to

pSettings Object

An object that holds settings for how the canera will behave.

pSettings.duration Object

An object that holds settings for how the canera will behave.

pSettings.duration.x number

The duration of the ease in the x dimension.

pSettings.duration.y number

The duration of the ease in the y dimension.

pSettings.ease Object

An object that holds settings for how the canera will behave.

pSettings.ease.x string

The ease to use in the x dimension.

pSettings.ease.y string

The ease to use in the y dimension.

pUpdateFunc Function

A callback that will be called when the camera is updated. pDiffX and pDiffY params are the difference in position between the last tick.

public cancelSpectate() source

Stops spectating. If the setting 'forcePos' was set. Then the camera will immedietly jump to the original camera target.

public detach() source

Detaches the camera. The camera is no longer the view eye.

public isMoving(): boolean source

Check if the camera is currently moving.

Return:

boolean

True if panning, false otherwise.

public isPanning(): boolean source

Check if the camera is currently panning.

Return:

boolean

True if panning, false otherwise.

public isShaking(): boolean source

Check if the camera is currently shaking.

Return:

boolean

True if shaking, false otherwise.

public isSpectating(): boolean source

Check if the camera is currently spectating.

Return:

boolean

True if spectating, false otherwise.

public isZooming(): boolean source

Check if the camera is currently zooming.

Return:

boolean

True if zooming, false otherwise.

public pan(pSettings: Object) source

Pans the camera from one view to another view. This pan can be customized in both axis. This pan has callbacks and settings that allow further customization.

Params:

NameTypeAttributeDescription
pSettings Object

A Object holding settings that control this pan.

pSettings.target Object

A Object holding settings that control this pan.

pSettings.ease Object

A Object holding settings that control this pan.

pSettings.ease.x string

A Object holding settings that control this pan.

pSettings.ease.y string

A Object holding settings that control this pan.

pSettings.panBackEase Object

A Object holding settings that control this pan.

pSettings.panBackEase.x string

A Object holding settings that control this pan.

pSettings.panBackEase.y string

A Object holding settings that control this pan.

pSettings.duration Object

A Object holding settings that control this pan.

pSettings.duration.x number

A Object holding settings that control this pan.

pSettings.duration.y number

A Object holding settings that control this pan.

pSettings.panBackDuration Object

A Object holding settings that control the duration of the pan.

pSettings.panBackDuration.x number

The duration of the ease in the x dimension.

pSettings.panBackDuration.y number

The duration of the ease in the y dimension.

pSettings.pauseDuration number

How long the camera will stay at the target after panning to it before completing the pan.

pSettings.attach boolean

Whether or not to attach the camera to the target when the pan to it is completed. This automatically forfeits the panBack nature of this and no panBack callback will be called.

pSettings.forceDirChange boolean

Whether panning to a target changes your direction to face the target.

pSettings.panToCallback Function

Callback function to be called when the pan to the target is completed.

pSettings.panBackCallback Function

Callback function to be called when the pan from the target back to the camera's target is completed.

public setSettings(pSettings: Object) source

Sets the camera to operate using these user defined settings.

Params:

NameTypeAttributeDescription
pSettings Object

An object that holds settings for how the canera will behave.

pSettings.duration Object

An object that holds settings for how the canera will behave.

pSettings.duration.x number

The duration of the ease in the x dimension.

pSettings.duration.y number

The duration of the ease in the y dimension.

pSettings.ease Object

An object that holds settings for how the canera will behave.

pSettings.ease.x string

The ease to use in the x dimension.

pSettings.ease.y string

The ease to use in the y dimension.

public shake(pIntensity: number, pDuration: number, pRotational: boolean, pCallback: Function) source

Shakes the camera with the passed settings.

Params:

NameTypeAttributeDescription
pIntensity number

The intensity of the shaking effect. 0 - 100

pDuration number

The duration of the shaking effect in ms.

pRotational boolean

Whether the shaking consists of rotational shaking as well.

pCallback Function

Callback function to call when the shaking is completed.

public spectate(pSettings: Object) source

Spectates another instance with the camera using the passed settings. If the location is over 1000m(pixels) away then the camera will automatically jump to that position no matter if forcePos is toggled or not.

Params:

NameTypeAttributeDescription
pSettings Object

Settings to control the spectate

pSettings.target Object

The instance to spectate

pSettings.forcePos boolean

If the camera should spectate instantly without easing to the location.

TODO:

  • Allow pSettings.target to also be a coordinate position, this will send the camera to that space and spectate that position.

public zoom(pDestinationLevel: Object, pDuration: number, pEase: Object, pCallback: Function) source

Zooms the camera in via the passed in arguments.

Params:

NameTypeAttributeDescription
pDestinationLevel Object

An object containing the zoom level information.

pDestinationLevel.x number

The x scale to zoom to.

pDestinationLevel.y number

The y scale to zoom to.

pDuration number

The duration of the zoom.

pEase Object

An object containing the ease information for how the zoom will be performed.

pEase.x string

The ease to use for the x scale zooming.

pEase.y string

The ease to use for the y scale zooming.

pCallback Function

The callback to call after the zoom ends.

Private Methods

private follow(pMethod: string, pElapsedMS: number) source

Method to follow the target of the camera.

Params:

NameTypeAttributeDescription
pMethod string

The method in which the camera is following.

pElapsedMS number

The amount of ms that has passed since the last tick.

private followLogic(pAxis: string, pPosition: Object, pMethod: string, pElapsedMS: number) source

The logic for following instances via the camera.

Params:

NameTypeAttributeDescription
pAxis string

'x' | 'y'. The axis to handle the logic in.

pPosition Object

The centered position of the target.

pMethod string

The method the camera is using to follow.

pElapsedMS number

The elapsed time since the last tick.

private getTrueCenterPos(pInstance: Object): Object source

Returns the true center position by using the x and y position and adding half of the icon's width / height. If no icon is found, we instead use the half of the default tileSize.

Params:

NameTypeAttributeDescription
pInstance Object

The instance to get the true center position of.

Return:

Object

Object containing the true center position of the instance.

private initCamera() source

Builds and initiates the camera and assigns some presets to it

private onPanFinish() source

Event handler for when the second part of the pan completes.

private onPanned() source

Event handler for when the first part of the pan completes.

private onShakeEnd() source

private onZoomEnd() source

private reset(pMethod: string) source

Resets the camera based on the method passed.

Params:

NameTypeAttributeDescription
pMethod string

The method to reset.

private shakeUpdate(pElapsedMS: number) source

The method to update shaking when it is active.

Params:

NameTypeAttributeDescription
pElapsedMS number

The amount of ms that has passed since the last tick.

private update(pElapsedMS: number) source

Update handler that is called each tick to update the camera's state

Params:

NameTypeAttributeDescription
pElapsedMS number

The amount of ms that has passed since the last tick

private zoomUpdate(pElapsedMS: number) source

The method to update the zoom when it is active.

Params:

NameTypeAttributeDescription
pElapsedMS number

The amount of ms that has passed since the last tick.