AnimationEffector

View source

Defines the base contract for effectors that apply interpolated animation values to entity components.

Concrete effectors specify the number of values in each keyframe and how those values are applied to their target component. Use a concrete effector with an AnimationTrack.

Examples

import { World } from '@wimaengine/ecs'
import { AnimationEffector, AnimationTrack } from '@wimaengine/animation'

class Opacity {
  value = 1
}

class OpacityAnimationEffector extends AnimationEffector {
  static apply(world, entity, results) {
    world.get(entity, Opacity).value = results[0]
  }

  static elementSize() {
    return 1
  }
}

const track = new AnimationTrack(OpacityAnimationEffector)
track.times = [0, 1]
track.keyframes = [0, 1]

const world = new World()
const entity = world.spawn([new Opacity()])
OpacityAnimationEffector.apply(world, entity, track.getCurrent(0.5))

Constructor


constructor()

Methods


staticapply(_world: World, _entity: EntityHandle, _results: number[]): void

View source

Applies interpolated values to an animation target.

The base implementation intentionally ignores every argument. A concrete effector should use world and entity to find the target component and write the values in results to it.

Parameters

NameDescriptionDefault
_world

World containing the target entity.

—
_entity

Handle of the entity to update.

—
_results

Interpolated values for the current keyframe.

—

staticelementSize(): number

View source

Returns the number of numeric values in each keyframe.

The base implementation returns 0. Concrete effectors must override it with the width expected by AnimationEffector.apply so that AnimationTrack can validate and interpolate flattened keyframes.

Returns

Always 0 for the base implementation.