Class
Position2DAnimationEffector
View sourceExtendsAnimationEffector
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
Properties
staticcomponentType: typeof Position2D
View sourceComponent constructor read by
Position2DAnimationEffector.apply. The method accesses this
through this.componentType, so a compatible subclass can replace the
constructor it looks up.
Default: Position2D
Methods
staticapply(world: World, entity: EntityHandle, results: number[]): void
View sourceWrites 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.
staticelementSize(): number
View sourceReturns the number of values consumed from each keyframe.
AnimationTrack therefore stores and interpolates two consecutive
values per timestamp for this effector.
