constructor(entity: EntityHandle)
View sourceCreates a remote transform that follows entity.
The copy flags start enabled and the offset starts as an identity affine.
Class
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.
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(entity: EntityHandle)Creates a remote transform that follows entity.
The copy flags start enabled and the offset starts as an identity affine.
Whether the source’s local position is copied to the target.
When false, the target keeps its current local position.
Default: true
Whether the source’s local orientation is copied to the target.
When false, the target keeps its current local orientation.
Default: true
Whether the source’s local scale is copied to the target.
When false, the target keeps its current local scale.
Default: true
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.
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: ...
copy(source: RemoteTransform2D, target?: RemoteTransform2D): RemoteTransform2DCopies 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.
clone(target: RemoteTransform2D): RemoteTransform2DCreates a copy of a remote transform.
default(): RemoteTransform2Dserialize(value: RemoteTransform2D): RemoteTransform2DSerialConverts 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.
validateSerial(value: unknown): value is RemoteTransform2DSerialChecks 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.
deserialize(value: RemoteTransform2DSerial, out?: RemoteTransform2D): RemoteTransform2DReconstructs 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.