Position2DTween

View source

ExtendsTween

Pairs with an entity’s Position2D component to animate its 2D position over time.

Attach Position2DTween to the same entity as Position2D and configure the app’s tween support. It inherits timing, easing, repeat, and flip behavior from Tween, using its from and to values to move the paired position between its start and end values.

Set duration to control how long the transition takes. Use repeat to replay it and flip to alternate the direction between cycles.

Examples

import { World } from '@wimaengine/ecs'
import { Position2D } from '@wimaengine/transform'
import { Position2DTween } from '@wimaengine/tween'

// Register DefaultTweenPlugin on the app that runs this world.
const world = new World()
world.spawn([
  new Position2D(0, 0),
  new Position2DTween(
    new Position2D(100, 50),
    new Position2D(0, 0),
    2
  )
])

Constructor


constructor(to: Position2D, from: Position2D, duration: number, repeat?: boolean, flip?: boolean, easing?: EasingFn)

View source

Creates tween state for an ending value, starting value, and duration.

Values are assigned directly; the constructor does not clone to or from, or validate duration. The optional booleans are stored on the instance; use TweenRepeat and TweenFlip to opt into repeated cycles and endpoint swapping.

Parameters

NameDescriptionDefault
to

Value passed to interpolation at progress 1.

—
from

Value passed to interpolation at progress 0.

—
duration

Total tween duration in seconds.

—
repeat?

Stored repeat option.

false
flip?

Stored flip option.

true
easing?

Function applied to normalized progress.

Easing.linear