Class AnimatedVector2

An animated 2D vector that can interpolate between animation keyframes over time. This class extends Vector2 and implements both IVector2 and IAnimatedValue interfaces, providing support for animation blending, looping, and time-based value updates.

Hierarchy (view full)

Implements

Constructors

Properties

_v: TypedArray = ...

Internal typed array storage for vector components

isLoop: boolean = true

Whether the animation should loop when it reaches the end.

Accessors

  • get blendingRatio(): number
  • Gets the current blending ratio between animation tracks.

    Returns number

    The current blending ratio

  • set blendingRatio(value): void
  • Sets the blending ratio between the first and second active animation tracks.

    Parameters

    • value: number

      The blending ratio (0.0 = first track only, 1.0 = second track only)

    Returns void

  • get glslStrAsFloat(): string
  • Converts the vector to a GLSL vec2 string representation with float precision.

    Returns string

    GLSL-compatible vec2 string

  • get glslStrAsInt(): string
  • Converts the vector to a GLSL ivec2 string representation with integer precision.

    Returns string

    GLSL-compatible ivec2 string

  • get wgslStrAsFloat(): string
  • Converts the vector to a WGSL vec2f string representation with float precision.

    Returns string

    WGSL-compatible vec2f string

  • get wgslStrAsInt(): string
  • Converts the vector to a WGSL vec2i string representation with integer precision.

    Returns string

    WGSL-compatible vec2i string

  • get z(): number
  • Gets the z component of the vector, updating the animation if necessary. Note: This always returns the z component even though this is a 2D vector.

    Returns number

    The z component value

  • get compositionType(): CompositionTypeClass<"VEC2">
  • Gets the composition type of this vector.

    Returns CompositionTypeClass<"VEC2">

    The composition type (Vec2)

Methods

  • Gets the component at the specified index.

    Parameters

    • i: number

      The index (0 for x, 1 for y)

    Returns number

    The component value at the specified index

  • Removes an animation sampler from the available tracks.

    Parameters

    • trackName: string

      The name of the animation track to remove

    Returns void

  • Gets all available animation track names.

    Returns string[]

    An array containing all animation track names

  • Gets the animation sampler for a specific track.

    Parameters

    • trackName: string

      The name of the animation track

    Returns AnimationSampler

    The animation sampler for the specified track

    When the specified animation track is not found

  • Gets the name of the first (primary) active animation track.

    Returns string

    The name of the first active animation track

  • Gets the maximum end time for a specific animation track.

    Parameters

    • trackName: string

      The name of the animation track

    Returns number

    The maximum end time (last input value) of the specified track

    When the specified animation track is not found

  • Gets the minimum start time for a specific animation track.

    Parameters

    • trackName: string

      The name of the animation track

    Returns number

    The minimum start time (first input value) of the specified track

    When the specified animation track is not found

  • Returns the current vector values as a regular JavaScript array.

    Returns number[]

    An array containing the x and y components of the vector

  • Gets the name of the second (secondary) active animation track.

    Returns undefined | string

    The name of the second active animation track, or undefined if not set

  • Checks if this vector is approximately equal to another vector within a tolerance.

    Parameters

    • vec: IVector2

      The vector to compare with

    • delta: number = Number.EPSILON

      The tolerance value (default: Number.EPSILON)

    Returns boolean

    True if vectors are approximately equal, false otherwise

  • Checks if the internal storage shares the same ArrayBuffer as the provided one. Useful for determining if vectors share underlying memory.

    Parameters

    • arrayBuffer: ArrayBuffer

      The ArrayBuffer to compare against

    Returns boolean

    True if the same ArrayBuffer is used, false otherwise

  • Adds or updates an animation sampler for a specific track.

    Parameters

    • animationTrackName: string

      The name of the animation track

    • animationSampler: AnimationSampler

      The animation sampler to associate with the track

    Returns void

  • Sets the first (primary) active animation track.

    Parameters

    • animationTrackName: string

      The name of the animation track to set as primary

    Returns void

    When the specified animation track is not found (logged as info instead)

  • Sets the internal Float32Array and triggers an update.

    Parameters

    • array: Float32Array

      The new Float32Array to use for the vector components

    Returns void

  • Sets the second (secondary) active animation track for blending.

    Parameters

    • animationTrackName: string

      The name of the animation track to set as secondary

    Returns void

    When the specified animation track is not found (logged as info instead)

  • Sets a specific time for animation evaluation instead of using global time.

    Parameters

    • time: number

      The time value to use for animation sampling

    Returns void

  • Updates the vector values based on the current time and active animation tracks. Handles looping, blending between tracks, and caching to avoid redundant calculations.

    Returns void

  • Switches back to using the global animation time instead of a specific time. This will cause the vector to use AnimationComponent.globalTime for updates.

    Returns void

  • Gets the component value at the specified index. Alias for the at() method for convenience.

    Parameters

    • i: number

      The index of the component to retrieve

    Returns number

    The component value at the given index

  • Calculates the dot product of two vectors (static version).

    Parameters

    Returns number

    The dot product of the two vectors

  • Calculates the squared length of a vector (static version). This is more efficient than calculating the actual length when only comparison is needed.

    Parameters

    • vec: IVector2

      The vector to calculate squared length for

    Returns number

    The squared length of the vector