TypeConverter
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
FloatTypeConverter / IntTypeConverter / DimenTypeConverter — 1 component
ColorTypeConverter — 4 components (alpha, red, green, blue)
IntSizeTypeConverter(seeAnimatedSize) — 2 components (width, height)
See also
Inheritors
Functions
Creates a zeroed AnimationVector shaped for T, typically via AnimationVector.ofSize.