Position2DAnimationEffector

View source

Applies interpolated 2D position values to an entity’s Position2D component.

This class implements the AnimationEffector contract for 2D position animation. Pass it to an AnimationTrack; each keyframe contains an x value followed by a y value.

Examples

import { World } from '@wimaengine/ecs'
import { AnimationTrack, Position2DAnimationEffector } from '@wimaengine/animation'
import { Position2D } from '@wimaengine/transform'

const world = new World()
const entity = world.spawn([new Position2D()])
const track = new AnimationTrack(Position2DAnimationEffector)
track.times = [0, 1]
track.keyframes = [0, 0, 10, 20]

Position2DAnimationEffector.apply(world, entity, track.getCurrent(0.5))
// The entity's position is now (5, 10).

Constructor


constructor()

Properties


Methods


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

View source

Writes the current x and y values to the target position component.

Position2DAnimationEffector.apply reads this.componentType from world for entity, then calls set(results[0], results[1]) on the returned component. 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 values; indexes 0 and 1 are x and y.

—

staticelementSize(): number

View source

Returns the number of values consumed from each keyframe.

AnimationTrack therefore stores and interpolates two consecutive values per timestamp for this effector.

Returns

Always 2.