InfluenceCamera provides multi-target weighted following inspired by Pro Camera 2D.

This camera is not attachable to targets. Instead, it's created at a specific location and targets can be subscribed to influence its position. Each subscriber has a weight (0.0-1.0) that determines how much influence they have on the camera's position.

When no subscribers remain, the camera smoothly returns to its base location. Multiple targets can be subscribed simultaneously with different influence weights.

const manager = CameraManager.getInstance();

// Create influence camera at base location
const influenceCam = manager.createInfluenceCamera(100, 200, 'map1');
influenceCam.setAsViewEye();

// Subscribe targets with different weights
influenceCam.subscribe(player, 0.7); // Player has 70% influence
influenceCam.subscribe(npc1, 0.3); // NPC has 30% influence
influenceCam.subscribe({ x: 50, y: 50 }, 0.1); // Position has 10% influence

// Update influence weights dynamically
influenceCam.updateInfluence(player, 0.9); // Increase player influence

// Unsubscribe when no longer needed
influenceCam.unsubscribe(npc1);

Hierarchy (View Summary)

Constructors

  • Creates a new InfluenceCamera instance

    Parameters

    • pId: string

      Unique identifier

    • pDiob: any

      VYLO Diob object

    • pX: number

      Initial X position

    • pY: number

      Initial Y position

    • pMapName: string

      Map name for the camera

    • pManager: any

      Reference to the CameraManager

    Returns InfluenceCamera

Properties

bounds: { maxX: number; maxY: number; minX: number; minY: number }

Camera position bounds (Infinity = no limit)

cachedCameraPos: Vector2D

Cached camera position to avoid object churn

cachedGizmoPos: Vector2D

Cached gizmo position to avoid object churn

cachedTransitionPos: Vector2D

Cached transition position to avoid object churn

diob: any

VYLO Diob object representing the camera

gizmoColor: number

Color used for gizmo visualization (hex value)

gizmoLineLength: number

The length of the gizmo line

id: string

Unique identifier for this camera instance

isViewEye: boolean

Whether this camera is currently the active view eye

manager: CameraManager

Reference to the CameraManager that owns this camera

operationIgnoreTimeScale: boolean

If true, this action ignores all time scale (global and camera)

operationTimeScale: null | number

Per-action override time scale (temporary), null when not set

owner: null | GameInstance | Vector2D

The owner/target this camera belongs to (GameInstance or Vector2D) This represents who the camera is attached to or following

position: Vector2D

Current position of the camera in world space

previousPosition: Vector2D

Previous position of the camera in world space (used for velocity tracking)

randomGizmoAngle: number

The random angle for the gizmo

timeScale: number

Camera-specific time scale multiplier (1.0 = normal)

trackTargetZ: boolean

Whether to track the target's Z position and subtract it from the Y position. Enabled by default. Useful for 2.5D isometric-style games where height (Z) affects screen Y.

transitionDurationX: number

Transition duration for X axis in milliseconds

transitionDurationY: number

Transition duration for Y axis in milliseconds

transitionEaseX: EaseType

Easing function for X axis transitions

transitionEaseY: EaseType

Easing function for Y axis transitions

transitioning: boolean

Whether this camera is currently transitioning to become the view eye

transitionProgress: number

Transition progress (0-1) when becoming view eye

transitionStartPos: Vector2D

Starting position for transitions

transitionTargetPos: Vector2D

Target position for transitions

transitionTime: number

Elapsed time for current transition

Camera type identifier

velocity: Vector2D

Current velocity of the camera in pixels per second

Accessors

  • get gizmoEnabled(): boolean
  • Getter for gizmoEnabled property

    Returns boolean

  • set gizmoEnabled(value: boolean): void
  • Setter for gizmoEnabled property that notifies CameraManager

    Parameters

    • value: boolean

    Returns void

  • get isActive(): boolean
  • Getter for isActive property

    Returns boolean

  • set isActive(value: boolean): void
  • Setter for isActive property that notifies CameraManager

    Parameters

    • value: boolean

    Returns void

  • get trackViewEyeZ(): boolean
  • Whether to track the view eye's Z position (alias for trackTargetZ)

    Returns boolean

  • set trackViewEyeZ(pValue: boolean): void
  • Parameters

    • pValue: boolean

    Returns void

Methods

  • Activates this camera, enabling updates

    Returns void

  • Applies global time scale to delta time for this camera

    Parameters

    • pDeltaTime: number

      Raw delta time

    Returns number

    Scaled delta time

  • Clamps camera position to bounds

    Returns void

  • Clears all camera bounds

    Returns void

    // Remove all bounds restrictions
    camera.clearBounds();
  • Deactivates this camera, disabling updates

    Returns void

  • Destroys this camera and cleans up resources

    Returns void

  • Gets whether auto-rebalance is enabled

    Returns boolean

    True if auto-rebalance is enabled

    const isAutoRebalance = camera.getAutoRebalance();
    console.log(`Auto-rebalance: ${isAutoRebalance ? 'ON' : 'OFF'}`);
  • Gets the base location of this influence camera

    Returns { mapName: string; x: number; y: number }

    Base location coordinates and map name

  • Gets the position where gizmos should be drawn for this camera

    Returns Vector2D

    Position for gizmo drawing (reuses cached object to avoid churn)

  • Gets the influence weight of a specific target

    Parameters

    Returns number

    Influence weight or 0 if not subscribed

  • Gets all current subscribers and their influence weights

    Returns Map<GameInstance | Vector2D, number>

    Map of subscribers and their weights

  • Gets the Z value of a target if trackTargetZ is enabled, else returns 0. Used to subtract target height from Y position for 2.5D depth effects.

    Parameters

    Returns number

    The target's z value, or 0 if tracking is disabled or target has no z

  • Gets this camera's time scale

    Returns number

  • Gets the current transition position

    Returns Vector2D

    Interpolated position based on transition progress

  • Gets the true camera position for a target (GameInstance or Vector2D) For GameInstance: returns center position (where camera should be) For Vector2D: returns the position directly Reuses cached object to avoid churn

    Parameters

    Returns Vector2D

  • Disables gizmo visualization for this camera

    Returns void

  • Invalidates the position cache to force recalculation Note: No longer needed since we calculate influence each frame

    Returns void

  • Checks if a target is currently subscribed

    Parameters

    Returns boolean

    True if subscribed, false otherwise

  • Checks if a target is a Vector2D (has x, y properties but no mapName)

    Parameters

    Returns pTarget is Vector2D

    True if target is Vector2D, false if GameInstance

  • Called when this camera is no longer the active view eye. Stops updating when not actively viewed.

    Returns void

  • Manually rebalances all influence weights to be equal

    Returns void

    // Manually rebalance all subscribers to equal weights
    camera.rebalanceInfluence();
  • Removes this camera from being the view eye and falls back to VYLO.Client.mob

    This is useful when you want to stop using a camera but keep it alive for potential future use. The camera will continue following its target but won't be the active view eye.

    Returns void

    // Stop using this camera but keep it following
    followCamera.removeViewEye(); // Falls back to VYLO.Client.mob
  • Resets this camera's time scale to 1.0

    Returns void

  • Resets ongoing transitions when time scale changes

    Returns void

  • Sets this camera as the active view eye.

    Automatically performs a smooth seamless transition from the current view eye using the manager's default transition settings (or custom options if provided). Pass { duration: 0 } to force an immediate instant cut.

    Parameters

    • OptionalpOptions: TransitionCameraOptions

      Optional transition options (duration, ease, matchVelocity, spring, etc.)

    Returns void

    // Smooth transition using defaults (500ms, easeInOutQuad, matchVelocity: true)
    camera.setAsViewEye();

    // Instant cut
    camera.setAsViewEye({ duration: 0 });

    // Custom transition
    camera.setAsViewEye({ duration: 800, ease: 'easeOutCubic' });
  • Sets the base location where the camera returns when no subscribers.

    Parameters

    • pX: number

      New X position

    • pY: number

      New Y position

    • pMapName: string

      New map name

    Returns void

    // Update base location
    camera.setBaseLocation(200, 300, 'map2');
  • Sets camera position bounds (Infinity = no limit in that direction)

    Parameters

    • pMinX: number

      Minimum X position (use -Infinity for no limit)

    • pMaxX: number

      Maximum X position (use Infinity for no limit)

    • pMinY: number

      Minimum Y position (use -Infinity for no limit)

    • pMaxY: number

      Maximum Y position (use Infinity for no limit)

    Returns void

    // Clamp camera to a 1000x1000 area starting at (0,0)
    camera.setBounds(0, 1000, 0, 1000);

    // Only clamp X axis, Y is free
    camera.setBounds(0, 1000, -Infinity, Infinity);
  • Sets the owner/target this camera belongs to

    Parameters

    Returns void

  • InfluenceCamera has its own movement API - setSettings should not be used Use subscribe/unsubscribe methods instead

    Parameters

    Returns void

  • Sets this camera's time scale

    Parameters

    • pScale: number

    Returns void

  • Sets whether the camera should track the target's Z position (subtracted from Y)

    Parameters

    • pEnabled: boolean

      Whether tracking is enabled

    Returns void

  • Sets whether the camera should track the view eye's Z position (alias for setTrackTargetZ)

    Parameters

    • pEnabled: boolean

      Whether tracking is enabled

    Returns void

  • Enables gizmo visualization for this camera. A colored dot will be drawn at the camera's position for debugging.

    Returns void

  • Subscribes a target to influence this camera's position.

    Each target can only be subscribed once. If already subscribed, this will update the influence weight.

    Parameters

    • pTarget: GameInstance | Vector2D

      GameInstance or Vector2D to subscribe

    • pInfluence: number

      Influence weight (0.0+, where 1.0 = full influence, 2.0 = double influence)

    Returns void

    // Subscribe player with 70% influence
    camera.subscribe(player, 0.7);

    // Subscribe boss with double influence (priority target)
    camera.subscribe(boss, 2.0);

    // Subscribe position with 30% influence
    camera.subscribe({ x: 100, y: 200 }, 0.3);
  • Subscribes a target with equal distribution (auto-rebalanced)

    Parameters

    Returns void

    // Subscribe player with equal distribution
    camera.subscribeEqual(player);
  • Unsubscribes a target from influencing this camera.

    Parameters

    Returns void

    // Unsubscribe player
    camera.unsubscribe(player);
  • Update method called each frame by CameraManager

    Parameters

    • pDeltaTime: number

      Time elapsed since last update in milliseconds

    Returns void

  • Updates the camera's diob position with proper view eye offset This is the same for all cameras - they all need to offset the diob to center the target on screen

    Returns void

  • Updates the influence weight for an existing subscriber. Sets manual mode (disables auto-rebalance)

    Parameters

    • pTarget: GameInstance | Vector2D

      GameInstance or Vector2D to update

    • pInfluence: number

      New influence weight (0.0+, where 1.0 = full influence, 2.0 = double influence)

    Returns void

    // Increase player influence
    camera.updateInfluence(player, 1.5);

    // Set boss to triple influence (very high priority)
    camera.updateInfluence(boss, 3.0);
  • Updates the transition progress

    Parameters

    • pDeltaTime: number

      Time elapsed since last update in milliseconds

    Returns boolean

    True if transition is complete

  • Updates the camera's velocity based on elapsed time and position change.

    Parameters

    • pDeltaTime: number

      Elapsed time in milliseconds

    Returns void