SpectateCamera provides smooth or instant transitions to observe targets.

Only one SpectateCamera can exist per target (GameInstance or Vector2D). Supports both instant positioning and eased transitions to targets.

When spectating with easing, the camera smoothly transitions to the target position and follows it. When spectating with instant positioning, the camera immediately jumps to the target and follows it from there.

const manager = CameraManager.getInstance();

// Create spectate camera
const spectateCam = manager.createSpectateCamera();

// Instant spectate to player
spectateCam.spectate(player, { forcePos: true });
spectateCam.setAsViewEye();

// Smooth spectate to position
spectateCam.spectate({ x: 100, y: 200 }, {
forcePos: false,
duration: 1000,
ease: 'easeOutCubic'
});

Hierarchy (View Summary)

Constructors

  • Creates a new SpectateCamera instance

    Parameters

    • pId: string

      Unique identifier

    • pDiob: any

      VYLO Diob object

    • pManager: any

      Reference to the CameraManager

    Returns SpectateCamera

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

  • Attaches this camera to always follow the player when not spectating.

    This ensures the camera is always positioned at the player's center and on the same map, ready for seamless transitions when spectating.

    Parameters

    Returns void

    // Make spectate camera always follow player
    spectateCamera.attach(VYLO.Client.mob);
  • Stops spectating and returns camera to its previous state.

    If the camera was transitioning, it stops at the current position. The camera remains active but no longer follows any target.

    Returns void

  • 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 the position where gizmos should be drawn for this camera

    Returns Vector2D

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

  • Gets the current target being spectated or followed

    Returns null | GameInstance | Vector2D

    The target or null if not spectating and no player target

  • 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

  • Checks if this camera is currently spectating

    Returns boolean

    True if spectating, false otherwise

  • Checks if this camera is currently transitioning to a target

    Returns boolean

    True if transitioning, 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. Can be overridden by subclasses to pause or clean up operations.

    Returns void

  • 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 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

  • SpectateCamera has its own movement API - setSettings should not be used Use spectate() method with options 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

  • Starts spectating a target with optional configuration.

    Only one SpectateCamera can spectate a given target at a time. If another SpectateCamera is already spectating the target, this camera will take over spectating duties.

    Parameters

    Returns void

    // Instant spectate to player
    camera.spectate(player, { forcePos: true });

    // Smooth spectate to position with custom settings
    camera.spectate({ x: 100, y: 200 }, {
    forcePos: false,
    duration: 2000,
    ease: 'easeInOutCubic'
    });
  • 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 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