# aego/tween

> Aego 0.12.5 · development; docs build `4a32b816933e02930662f6a443cb25abe6050d090c55e237cbff5c44ae9b25f8`. [Build manifest](/docs-build.json).

A tween returns a handle: chain `Delay`, `Loop`, `PingPong` or `Unscaled` right after creating it, `yield` it in a coroutine to wait for the end, or connect to `Completed`. A new tween on the same property replaces the running one. In a project, attach it to a node with a Sprite Renderer. See [Tweens](/tween.md).

## Example

```aes run
package demo

import (
    "aego/curve"
    "aego/log"
    "aego/tween"
)

script Pickup {
    var pulse tween.Tween

    func Ready() {
        pulse = tween.ToVec2(node, "transform.scale", Vec2{1.2, 1.2}, 0.25, curve.InOutSine).PingPong(-1)
        start Fly()
    }

    func Fly() coroutine {
        yield tween.Position(node, Vec2{3, -1}, 0.5, curve.OutCubic)
        log.Info("arrived at " + string(node.Position().X) + ", " + string(node.Position().Y))
        fade := tween.ToFloat(node, "SpriteRenderer.Tint.a", 0, 0.5, curve.Linear).Delay(0.25)
        fade.Completed.Connect(OnFaded)
        yield fade
        pulse.Stop()
        log.Info("pulse running: " + string(pulse.Running()))
    }

    func OnFaded(finished bool) {
        log.Info("fade finished: " + string(finished))
    }
}
```

## Position

```
func Position(node NodeRef, to Vec2, duration float, ease aego/curve.Easing) Handle<aego/tween.Tween>
```

Moves a 2D node to a local position.

## ToColor

```
func ToColor(node NodeRef, path string, to Color, duration float, ease aego/curve.Easing) Handle<aego/tween.Tween>
```

Animates a Color property.

## ToFloat

```
func ToFloat(node NodeRef, path string, to float, duration float, ease aego/curve.Easing) Handle<aego/tween.Tween>
```

Animates a float or int property, or one lane of a vector or color.
Paths: Component.Field, Component.Field.a, transform.rotation, script/Name.Field.

## ToQuat

```
func ToQuat(node NodeRef, path string, to Quat, duration float, ease aego/curve.Easing) Handle<aego/tween.Tween>
```

Turns a rotation along the short arc.

## ToVec2

```
func ToVec2(node NodeRef, path string, to Vec2, duration float, ease aego/curve.Easing) Handle<aego/tween.Tween>
```

Animates a Vec2 property.

## ToVec3

```
func ToVec3(node NodeRef, path string, to Vec3, duration float, ease aego/curve.Easing) Handle<aego/tween.Tween>
```

Animates a Vec3 property, such as the position of a 3D node.
