Scale2DAnimationEffector

View source

Writes two interpolated scale values from an AnimationTrack to an entity’s Scale2D component.

Use the class itself as the track effector. Each keyframe contains the local scale’s x and y values. apply() receives the interpolated values, target World, and EntityHandle. The target entity must already have an Scale2D component.

Examples

import { World } from '@wimaengine/ecs'
import { AnimationTrack, Scale2DAnimationEffector } from '@wimaengine/animation'
import { Scale2D } from '@wimaengine/transform'

const world = new World()
const entity = world.spawn([new Scale2D()])
const track = new AnimationTrack(Scale2DAnimationEffector)
track.times = [0, 1]
track.keyframes = [1, 1, 2, 0.5]

Scale2DAnimationEffector.apply(world, entity, track.getCurrent(0.5))
// The component now contains the scale (1.5, 0.75).

Constructor


constructor()

Properties


staticcomponentType: typeof Scale2D

View source

Component constructor used by Scale2DAnimationEffector.apply when it reads the target from the world. A compatible subclass can replace this value and the inherited apply method will use that constructor through this.componentType.

Default: Scale2D

Methods


staticapply(world: World, entity: EntityHandle, results: number[]): void

View source

Writes the interpolated x and y values to the target scale.

The method calls world.get(entity, this.componentType), then passes results[0] and results[1] to the returned component’s set() method. It does not add a missing component or check the lookup result. A stale handle, an unknown entity, or an entity without the component therefore causes the subsequent set() call to fail.

Parameters

NameDescriptionDefault
world

World containing the target entity.

—
entity

Handle of the entity to update.

—
results

Interpolated scale values; indexes 0 and 1 are x and y.

—

staticelementSize(): number

View source

Returns the number of values consumed from each keyframe.

AnimationTrack uses this width when validating and interpolating the flattened keyframe array for this effector.

Returns

Always 2.