Aego Русский

aego/tween

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.

On this page

Example

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))
    }
}

Functions

Position(node NodeRef, to Vec2, duration float, ease aego/curve.Easing) Handle<aego/tween.Tween>Moves a 2D node to a local position.
ToColor(node NodeRef, path string, to Color, duration float, ease aego/curve.Easing) Handle<aego/tween.Tween>Animates a Color property.
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.
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(node NodeRef, path string, to Vec2, duration float, ease aego/curve.Easing) Handle<aego/tween.Tween>Animates a Vec2 property.
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.
TweenTween animates one property of a node. A finished, stopped or nil tween reads as done; yield t waits until it ends.

Position function

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

Moves a 2D node to a local position.

Example

yield tween.Position(node, Vec2{4, 0}, 0.5, curve.OutCubic)

ToColor function

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

Animates a Color property.

Example

tween.ToColor(node, "SpriteRenderer.Tint", HitTint, 0.2, curve.Linear)

ToFloat function

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.

Example

tween.ToFloat(node, "SpriteRenderer.Tint.a", 0, 0.3, curve.OutQuad)

ToQuat function

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.

Example

tween.ToQuat(node, "transform.rotation", math.QuatEuler(0, 1.57, 0), 0.5, curve.InOutCubic)

ToVec2 function

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

Animates a Vec2 property.

Example

tween.ToVec2(node, "transform.scale", Vec2{1.2, 1.2}, 0.1, curve.OutBack)

ToVec3 function

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.

Example

tween.ToVec3(node, "transform.position", Vec3{0, 2, 0}, 1, curve.InOutSine)