TypeConverter

interface TypeConverter<T>

Converts a value of type T to and from the AnimationVector the animation system runs on. Each animated type decomposes into a fixed set of float components — 1 for a scalar like Float, 2 for a size, 4 for a color — and the spring/tween machinery drives each component on its own, so a multi-component value carries a real per-component value and per-component velocity rather than being collapsed to one lossy scalar.

newVector mints an empty vector of the right shape (via AnimationVector.ofSize); toVector writes a value's components into a caller-owned vector so a per-frame animation allocates nothing.

A custom animated type implements all three methods, e.g. for a 3-component value:

object PointConverter : TypeConverter<Point> {
override fun newVector(): AnimationVector = AnimationVector.ofSize(3)
override fun toVector(value: Point, vector: AnimationVector) {
vector[0] = value.x
vector[1] = value.y
vector[2] = value.z
}
override fun fromVector(vector: AnimationVector): Point =
Point(vector[0], vector[1], vector[2])
}

Built-in Converters

See also

Inheritors

Functions

Link copied to clipboard
abstract fun fromVector(vector: AnimationVector): T

Reconstructs a T from a vector produced by this converter.

Link copied to clipboard
abstract fun newVector(): AnimationVector

Creates a zeroed AnimationVector shaped for T, typically via AnimationVector.ofSize.

Link copied to clipboard
abstract fun toVector(value: T, vector: AnimationVector)

Writes value's components into vector, which is shaped by this converter's newVector.