AnimationTarget

View source

Associates an entity with an animation player and an animation track key.

player identifies the entity that owns AnimationPlayer. id identifies the corresponding track key in AnimationClip for the entity that owns this component.

The component stores the player entity link and track key supplied to its constructor. It does not validate that the entity is alive or that the key exists in an animation clip.

serialize() delegates the player field to EntityHandle.serialize(). deserialize() delegates it to EntityHandle.deserialize(), so callers should account for the different nested handle representations currently used by those two helpers. validateSerial() checks the outer shape only; it does not verify that the player handle identifies a live entity.

Examples

import { EntityHandle, Query, World } from '@wimaengine/ecs'
import { AnimationPlayer, AnimationTarget } from '@wimaengine/animation'

const world = new World()
const player = world.spawn([new AnimationPlayer()])
const target = world.spawn([
  new AnimationTarget(player, 'opacity')
])

new Query(world, [EntityHandle, AnimationTarget]).each(([entity, animationTarget]) => {
  if (entity.equals(target)) {
    console.log(animationTarget.player.equals(player)) // true
    console.log(animationTarget.id) // 'opacity'
  }
})

Constructor


constructor(player: EntityHandle, id: string)

View source

Creates an animation target component.

The supplied player handle and track key are stored directly. The constructor does not validate the handle or look up the track key.

Parameters

NameDescriptionDefault
player

Entity that owns the AnimationPlayer component.

—
id

Key of the animation tracks to apply.

—

Properties


player: EntityHandle

View source

Entity handle for the entity that owns the AnimationPlayer component.

This is the handle supplied to the constructor or copied from another target. Reading it does not query the world or confirm that the entity is still alive.

id: string

View source

Animation track key for this target.

This is the string supplied to the constructor or copied from another target. It identifies the track in the active AnimationClip that applies to this entity.

Methods


staticcopy(source: AnimationTarget, target?: AnimationTarget): AnimationTarget

View source

Copies an animation target into another component.

The player handle is assigned by reference and is not cloned. If target is omitted, a new component is created and populated.

Parameters

NameDescriptionDefault
source

Target component to copy.

—
target?

Component to populate.

...

Returns

The populated target component.

staticclone(target: AnimationTarget): AnimationTarget

View source

Creates a shallow copy of an animation target.

The returned component has the same id and shares the source’s EntityHandle object because this method delegates to copy().

Parameters

NameDescriptionDefault
target

Target component to clone.

—

Returns

A new target component.

staticserialize(value: AnimationTarget): AnimationTargetSerial

View source

Converts an animation target to its serialized fields.

The returned object contains id and the result of EntityHandle.serialize(value.player) in player. That nested result is the handle’s {index, generation} object, not the packed numeric value returned by value.player.id().

Parameters

NameDescriptionDefault
value

Target component to serialize.

—

Returns

Serialized target fields.

staticdeserialize(value: AnimationTargetSerial, out?: AnimationTarget): AnimationTarget

View source

Reconstructs an animation target from serialized fields.

If out is supplied, its player handle is updated in place and its id is replaced. Otherwise, a target with a placeholder handle is created. The current implementation passes value.player to EntityHandle.deserialize(), which expects a packed numeric entity id, while serialize() currently writes the object returned by EntityHandle.serialize(). Adapt the nested player value when restoring the direct output of serialize().

Parameters

NameDescriptionDefault
value

Serialized target fields.

—
out?

Component to populate and return.

...

Returns

The populated target component.

staticvalidateSerial(value: unknown): value is AnimationTargetSerial

View source

Checks the serialized shape accepted by an animation target.

For a non-null object, validation requires a truthy player field and a string id field. It does not validate the nested player representation, check whether the handle is live in a world, or check that the id names a track in an animation clip. The current implementation does not guard against null, so callers should pass a non-null object.

Parameters

NameDescriptionDefault
value

Value to validate.

—

Returns

Whether the outer shape is valid.