RemoteTransform2D

View source

Copies selected local 2D transform channels from a source entity to the entity that owns this component.

Add this component together with Position2D, Orientation2D, and Scale2D. The entity handle identifies the source. Position, orientation, and scale can be copied independently with the three copy* flags. All three flags default to true, so a newly constructed component follows the complete source transform.

When the source handle is missing or stale, or the source does not have all three local transform components, the target is left unchanged. The offsetTransform is decomposed while the selected channels are copied. Its translation is added to the source position, its orientation is combined with the source orientation, and its scale is multiplied by the source scale. The default new Affine2() is the identity transform, so it adds no translation, rotation, or scale.

Enable RemoteTransform2DPlugin to apply this component during the app’s transform updates.

Examples

import { World } from '@wimaengine/ecs'
import {
  Orientation2D,
  Position2D,
  RemoteTransform2D,
  Scale2D
} from '@wimaengine/transform'

const world = new World()
const source = world.spawn([
  new Position2D(40, 20),
  new Orientation2D(),
  new Scale2D()
])

const remote = new RemoteTransform2D(source)
remote.copyOrientation = false
world.spawn([
  new Position2D(),
  new Orientation2D(),
  new Scale2D(),
  remote
])

// With RemoteTransform2DPlugin enabled, the follower copies the source's
// position and scale while retaining its own orientation.

Constructor


constructor(entity: EntityHandle)

View source

Creates a remote transform that follows entity.

The copy flags start enabled and the offset starts as an identity affine.

Parameters

NameDescriptionDefault
entity

Source entity handle.

—

Properties


copyTranslation: boolean

View source

Whether the source’s local position is copied to the target.

When false, the target keeps its current local position.

Default: true

  • @defaultValue `true`

copyOrientation: boolean

View source

Whether the source’s local orientation is copied to the target.

When false, the target keeps its current local orientation.

Default: true

  • @defaultValue `true`

copyScale: boolean

View source

Whether the source’s local scale is copied to the target.

When false, the target keeps its current local scale.

Default: true

  • @defaultValue `true`

entity: EntityHandle

View source

Generation-aware handle of the source entity whose local 2D transform is followed.

The handle contains an entity slot index and generation. The generation prevents a despawned entity’s slot from accidentally referring to a later entity that reuses the same slot.

offsetTransform: Affine2

View source

Affine offset applied to the copied transform channels.

The value is decomposed whenever the transform is updated. Its translation is added to a copied position, its orientation is combined with a copied orientation, and its scale is multiplied by a copied scale. It starts as the identity Affine2.

Default: ...

Methods


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

View source

Copies all remote-transform settings into a component.

The source handle is assigned to the target, while the offset affine is copied into a new Affine2 so later offset edits do not share the same affine object.

Parameters

NameDescriptionDefault
source

Component to copy.

—
target?

Component to populate.

...

Returns

The populated target.

staticserialize(value: RemoteTransform2D): RemoteTransform2DSerial

View source

Converts a remote transform to its serialized field representation.

The three flags are written as booleans. The entity field is delegated to EntityHandle.serialize, and the offset field is delegated to Affine2.serialize.

Parameters

NameDescriptionDefault
value

Component to serialize.

—

Returns

Serialized fields.

staticvalidateSerial(value: unknown): value is RemoteTransform2DSerial

View source

Checks the shape and serialized values accepted by this component.

Validation requires all three boolean flags, an entity value accepted by EntityHandle.validateSerial, and a six-number affine value accepted by Affine2.validateSerial. It checks representation only; it does not verify that the entity is alive in a world.

The entity serializer and validator currently use different representations: serialize() writes the {index, generation} object returned by EntityHandle.serialize, while this validator forwards its input to EntityHandle.validateSerial, which accepts a packed numeric entity ID.

Parameters

NameDescriptionDefault
value——

Returns

Whether value has the required serialized shape.

staticdeserialize(value: RemoteTransform2DSerial, out?: RemoteTransform2D): RemoteTransform2D

View source

Reconstructs a remote transform from serialized fields.

The flags are copied directly. The entity field is passed to EntityHandle.deserialize, and the affine field is passed to Affine2.deserialize; neither value is normalized by this method. If out is provided, its entity and offset objects are updated in place. The default output starts with a zero handle and an identity offset.

Parameters

NameDescriptionDefault
value

Serialized fields. Its entity value must satisfy the input contract of EntityHandle.deserialize.

—
out?

Optional component to populate.

...

Returns

The populated or newly created component.