Orientation2DAnimationEffector

View source

Converts one interpolated angle into an entity’s Orientation2D component value.

Pass this class itself to AnimationTrack. Each keyframe contains a single angle in radians. Orientation2DAnimationEffector.apply looks up the component in the target World using its EntityHandle, converts the angle with Rotary.fromAngle, and copies the resulting cosine/sine pair into the component. The entity must already have the component when the animation runs.

Examples

import { World } from '@wimaengine/ecs'
import { AnimationTrack, Orientation2DAnimationEffector } from '@wimaengine/animation'
import { Orientation2D } from '@wimaengine/transform'

const world = new World()
const entity = world.spawn([new Orientation2D()])
const track = new AnimationTrack(Orientation2DAnimationEffector)
track.times = [0, 1]
track.keyframes = [0, Math.PI]

Orientation2DAnimationEffector.apply(world, entity, track.getCurrent(0.5))
// The entity is now rotated by a quarter turn (PI / 2 radians).

Constructor


constructor()

Properties


Methods


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

View source

Converts the current angle and writes it to the target orientation.

The method reads this.componentType from world for entity, creates a Rotary with Rotary.fromAngle(results[0]), and copies that value into the returned component. The angle is interpreted in radians. 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 copy() call to fail.

Parameters

NameDescriptionDefault
world

World containing the target entity.

—
entity

Handle of the entity to update.

—
results

Interpolated values; index 0 is the angle in radians.

—

staticelementSize(): number

View source

Returns the number of values consumed from each keyframe.

AnimationTrack therefore stores and interpolates one angle per timestamp for this effector.

Returns

Always 1.