CameraManager is the central singleton that manages all camera instances in the Lens system.

Responsibilities:

  • Creating and destroying cameras
  • Managing camera lifecycle and updates (automatic RAF loop or manual)
  • Handling view eye transitions
  • Loading and providing shake presets
  • Rendering debug gizmos

The CameraManager can operate in two modes:

  1. Auto-start mode (default): Automatically starts its own RAF loop when created
  2. Manual mode: Requires manual calls to update() in your own update loop
// Auto-start mode (default behavior)
const manager = new CameraManager();

// Create cameras - they update automatically
const followCam = manager.createFollowCamera();
const spectateCam = manager.createSpectateCamera();

// Use cameras - no manual update needed
manager.followTarget(followCam, target);
manager.spectateTarget(spectateCam, target);

// Manual mode for custom update loops
const manager = new CameraManager({ autoStart: false });

function gameLoop(elapsedMs: number, timeScale: number) {
// Your game logic here
manager.update(elapsedMs, timeScale); // Call this in your update loop
}

// Clean up when done
manager.destroyCamera(followCam.id);

Constructors

  • Creates a new CameraManager instance

    Each CameraManager instance manages its own cameras and RAF loop. You can create multiple instances for different camera systems.

    Parameters

    • OptionalpOptions: CameraManagerOptions

      Configuration options for the camera manager

      • OptionalautoStart?: boolean

        Whether to automatically start the camera manager

      • Optionaldebug?: boolean | CameraDebugOptions

        Debug gizmos configuration

      • OptionaldefaultTransition?: TransitionCameraOptions

        Global default transition options used when switching cameras

    Returns CameraManager

    // Auto-start RAF loop (default behavior)
    const manager = new CameraManager();

    // Manual update control
    const manager = new CameraManager({ autoStart: false });
    // Call manager.update(elapsedMs, timeScale) in your own update loop

Methods

  • Creates a new FollowCamera instance and auto-creates pan/spectate cameras

    Returns FollowCamera

    The created FollowCamera

    const camera = manager.createFollowCamera();
    camera.attach(player);
    camera.setAsViewEye();
  • Creates a new InfluenceCamera instance

    Parameters

    • pX: number

      Initial X position

    • pY: number

      Initial Y position

    • pMapName: string

      Map name for the camera

    Returns InfluenceCamera

    The created InfluenceCamera

    const camera = manager.createInfluenceCamera(100, 200, 'map1');
    camera.subscribe(player, 0.7);
    camera.subscribe(npc, 0.3);
    camera.setAsViewEye();
  • Creates a new PanCamera instance

    Returns PanCamera

    The created PanCamera

    const camera = manager.createPanCamera();
    camera.pan({ x: 100, y: 200 }, { duration: 1000, panBack: true });
    camera.setAsViewEye();
  • Creates a new SpectateCamera instance

    Returns SpectateCamera

    The created SpectateCamera

    const camera = manager.createSpectateCamera();
    camera.spectate(player, { forcePos: false, duration: 1000 });
    camera.setAsViewEye();
  • Creates a new TransitionCamera instance

    Returns TransitionCamera

    The created TransitionCamera

    const camera = manager.createTransitionCamera();
    await camera.transition(targetCamera, { duration: 1000, ease: 'easeInOutQuad' });
  • Destroys a camera and removes it from management.

    If the destroyed camera is currently the active view eye, the system will automatically fall back to the default VYLO mob camera.

    Parameters

    • pId: string

      ID of the camera to destroy

    Returns void

    // Destroy a camera - if it's the active view eye, falls back to mob camera
    manager.destroyCamera(camera.id);
  • Automatically transitions to a FollowCamera and performs the attach action. If already using a FollowCamera for the same target, executes the action directly.

    Parameters

    Returns Promise<void>

    const followCam = manager.createFollowCamera();
    manager.followTarget(followCam, target, { x: 0, y: 0, z: 0 });
  • Gets all cameras managed by this CameraManager

    Returns BaseCamera[]

    Array of all camera instances

  • Gets the auto-created pan camera

    Returns null | PanCamera

    The auto pan camera or null if none exists

  • Gets the auto-created spectate camera

    Returns null | SpectateCamera

    The auto spectate camera or null if none exists

  • Gets the auto-created transition camera

    Returns null | TransitionCamera

    The auto transition camera or null if none exists

  • Gets a camera by ID

    Parameters

    • id: string

      Camera ID

    Returns undefined | BaseCamera

    The camera or undefined if not found

  • Gets cameras of a specific type

    Parameters

    • pType: string

      Camera type to filter by

    Returns BaseCamera[]

    Array of cameras of the specified type

  • Gets whether cameras ignore the global time scale

    Returns boolean

  • Gets the current shake preset name (if any)

    Returns null | ShakePreset

    Current shake preset name or null

  • Gets the currently active view eye camera

    Returns null | BaseCamera

    The current view eye camera or null

  • Gets the current zoom level of the mapView

    Returns Vector2D

    Vector2D containing current X and Y zoom levels

  • Gets the debug center lines visibility setting

    Returns boolean

    True if debug center lines are enabled

  • Gets the native GizmoRenderer instance if initialized.

    Returns null | GizmoRenderer

  • Gets the global gizmo visibility setting

    Returns boolean

    True if gizmos are globally enabled

  • Gets the global base offsets (cached object, no object churn)

    Returns Readonly<{ x: number; y: number }>

    Read-only cached object with x and y offsets

  • Returns number

  • Returns boolean

  • Returns boolean

  • Gets the current main follow camera

    Returns null | FollowCamera

    The main follow camera or null if none set

  • Gets a shake preset by name

    Parameters

    Returns undefined | ShakePresetConfig

    The shake preset configuration or undefined if not found

  • Gets the current global time scale factor (alias for getGlobalTimeScale)

    Returns number

  • Handles the end of panning by a PanCamera.

    Parameters

    • pPanCamera: PanCamera

      The camera that stopped panning

    Returns void

  • Handles the start of panning by a PanCamera.

    Cancels any conflicting camera operations (spectate, other pan). Optimized to only iterate over relevant camera types.

    Parameters

    • pPanCamera: PanCamera

      The camera that started panning

    Returns void

  • Handles the end of spectating by a SpectateCamera.

    Parameters

    Returns void

  • Handles the start of spectating by a SpectateCamera.

    Cancels any conflicting camera operations (pan, other spectate). Only iterate over relevant camera types.

    Parameters

    Returns void

  • Handles a request to change the view eye to a new camera.

    Called internally by BaseCamera.setAsViewEye(). Automatically performs a smooth transition from the current view eye using default or custom settings, unless pOptions.duration is explicitly set to 0.

    Parameters

    Returns void

  • Handles when a camera is detached and was the view eye

    Parameters

    • pDetachedCamera: BaseCamera

      The camera that was detached

    Returns void

  • Checks if the camera is currently shaking

    Returns boolean

    True if shaking is active

  • Checks if the camera is currently zooming

    Returns boolean

    True if zooming is active

  • Subscribes a listener to camera system events.

    Type Parameters

    Parameters

    Returns () => void

    An unsubscribe function to remove the listener

    const unsub = manager.on('shake-start', (data) => {
    console.log('Shake started:', data.preset);
    });
    // Later: unsub();
  • Automatically transitions to the auto-created PanCamera and performs the pan action. If already using a PanCamera, executes the action directly.

    Parameters

    Returns Promise<void>

    // Pan to a position
    manager.panTo({ x: 100, y: 200 }, { duration: 1000, ease: 'easeOutCubic' });

    // Pan to a GameInstance
    manager.panTo(player, { duration: 500, panBack: true });
  • Sets whether cameras ignore the global time scale

    Parameters

    • pIgnore: boolean

    Returns void

  • Sets debug center lines visibility

    Parameters

    • pEnabled: boolean

      Whether debug center lines should be visible

    Returns void

  • Sets global gizmo visibility for all cameras Optimized to use cached gizmo-enabled cameras

    Parameters

    • pEnabledOrOptions: boolean | CameraDebugOptions

      Boolean to toggle or detailed options object.

    Returns void

    manager.setDebugMode(true);
    // or
    manager.setDebugMode({
    showCameraMarkers: true,
    showTargetLines: true,
    showBounds: true,
    showCenterCrosshair: true,
    bounds: { minX: 0, maxX: 1920, minY: 0, maxY: 1080 }
    });
  • Sets specific debug overlay options.

    Parameters

    Returns void

  • Sets the global default transition settings for camera switches.

    Parameters

    Returns void

  • Sets global gizmo visibility for all cameras

    Parameters

    • pEnabled: boolean

      Whether gizmos should be visible

    Returns void

  • Sets the global base offsets for the view eye

    These offsets will be used as the default when shake effects wear off. They provide a way to set a permanent offset for the entire view eye.

    Parameters

    • pX: number

      X offset in pixels

    • pY: number

      Y offset in pixels

    Returns void

    // Set a permanent 10px right, 5px down offset
    manager.setGlobalOffsets(10, 5);

    // When shake wears off, it will return to these offsets instead of (0, 0)
    manager.shakePreset('gunshot');
    // After shake completes, view eye returns to (10, 5) offset
  • Sets the global time scale factor for all cameras and effects

    Parameters

    • pTimeScale: number

      Time scale factor (1.0 = normal speed, 0.5 = half speed, 2.0 = double speed)

    Returns void

    // Slow down everything to half speed
    manager.setGlobalTimeScale(0.5);

    // Speed up everything to double speed
    manager.setGlobalTimeScale(2.0);

    // Reset to normal speed
    manager.setGlobalTimeScale(1.0);
  • Sets whether global effects (shake, zoom) ignore time scale

    Parameters

    • pIgnore: boolean

      Whether effects should ignore time scale

    Returns void

    // Make effects immune to time scale changes
    manager.setEffectsIgnoreTimeScale(true);

    // Allow effects to be affected by time scale
    manager.setEffectsIgnoreTimeScale(false);
  • Parameters

    • pIgnore: boolean

    Returns void

  • Sets the main follow camera that will automatically become the view eye when other cameras (spectate, pan) end their operations.

    Parameters

    • pFollowCamera: FollowCamera

      The follow camera to set as main

    • pTarget: GameInstance | Vector2D

      Target to attach the camera to (GameInstance or Vector2D)

    • OptionalpOffsets: Partial<CameraOffset>

      Optional offsets for the camera

    • OptionalpSetAsViewEye: boolean

      Whether to immediately set this camera as the view eye

    Returns FollowCamera

    The follow camera for method chaining

    const manager = new CameraManager();
    const mainCamera = manager.createFollowCamera();
    const camera = manager.setMainFollowCamera(mainCamera, player, { x: 0, y: 0, z: 0 }, true);

    // Now when spectate/pan ends, it will automatically resume this camera
  • Sets the global time scale factor for all cameras and effects (alias for setGlobalTimeScale)

    Parameters

    • pTimeScale: number

      Time scale factor

    Returns void

  • Applies custom shake to the active view eye camera

    Parameters

    Returns void

    // Custom shake
    manager.shake({
    strength: { x: 5, y: 3 },
    duration: { x: 500, y: 500 },
    vibrato: 15,
    infinite: false
    });
  • Applies a shake preset to the active view eye camera

    Parameters

    • pPresetName: ShakePreset

      Name of the shake preset

    • OptionalpCallback: () => void

      Optional callback when shake completes

    • OptionalpInfiniteOverride: boolean

      Optional flag to override preset's infinite setting

    Returns void

    // Apply gunshot shake
    manager.shakePreset('gunshot');

    // Apply infinite handheld shake
    manager.shakePreset('handheld-soft', undefined, true);
  • Automatically transitions to the auto-created SpectateCamera and performs the spectate action. If already using a SpectateCamera, executes the action directly.

    Parameters

    Returns Promise<void>

    // Spectate a position
    manager.spectateTarget({ x: 100, y: 200 }, { duration: 500, ease: 'easeOutCubic' });

    // Spectate a GameInstance
    manager.spectateTarget(player, { duration: 1000, forcePos: false });
  • Stops the internal RAF loop. Only needed for cleanup or if you want to pause the system.

    Returns void

  • Stops the current shake effect

    Returns void

  • Stops the current zoom effect

    Returns void

  • Switches from current view eye to target camera smoothly via TransitionCamera. If no view eye is active or duration is 0, switches directly without transition.

    Parameters

    Returns Promise<void>

    Promise that resolves when the transition completes

    await manager.switchTo(bossCamera, { duration: 1000, ease: 'easeInOutQuad' });
    
  • Public update method - can be called manually or automatically by RAF loop. Updates all active cameras, global effects, and gizmos.

    Parameters

    • pElapsedMs: number

      Time elapsed since last update in milliseconds

    Returns void

    // Manual update control
    const manager = new CameraManager({ autoStart: false });

    function gameLoop(elapsedMs: number, timeScale: number) {
    // Your game logic here
    manager.update(elapsedMs, timeScale);
    }
  • Automatically transitions to an InfluenceCamera at the specified location.

    Parameters

    • pX: number

      X position for the influence camera

    • pY: number

      Y position for the influence camera

    • pMapName: string

      Map name for the influence camera

    Returns Promise<void>

    // Automatically switches to InfluenceCamera at position
    manager.useInfluenceCamera(100, 200, 'map1');
  • Applies zoom to the active view eye camera

    Parameters

    • OptionalpDestinationLevel: number | { x?: number; y?: number }

      Target zoom level (number or {x, y} object)

    • OptionalpDuration: number | DurationSettings

      Duration in milliseconds (number or {x, y} object)

    • OptionalpEase: EaseType | EaseSettings

      Easing function (string or {x, y} object)

    • OptionalpCallback: () => void

      Optional callback when zoom completes

    • OptionalpOptions: { ignoreTimeScale?: boolean; timeScale?: number }

    Returns void

    // Simple zoom
    manager.zoom(2.0, 1000);

    // Different zoom per axis
    manager.zoom({ x: 2.0, y: 1.5 }, { x: 1000, y: 1500 });