Tween

This module contains functions and classes for creating and managing tween animations. Tweening is the process of generating intermediate frames between two keyframes to create the illusion of smooth motion or transformation. This module provides a variety of easing functions and utilities to facilitate the creation of complex animations with minimal effort.

To use this component, add the following line to your project file:

require engine.tweener.tween // or require engine.core

Example:

var tween = scale_tween(levelNode, float3(2, 1, 2), 10.).on_complete(@() { print("done"); })
tween.on_complete() @() {
    print("done")
}

var seq = create_tween_seq()
var bumpTween = position_tween(nodeId, nodeId.localPosition + float3(0., 0.1, 0), 0.2, @@inOutQuintic)
bumpTween.set_loops(-1, LoopType.Yoyo)
next(seq, bumpTween)

var scaleTween = scale_tween(nodeId, float3(0.65, 0.7, 0.7), 0.2, @@inOutQuintic)
scaleTween.set_loops(-1, LoopType.Yoyo)
join(seq, scaleTween)

Enumerations

LoopType

Specifies the looping behavior for tween.

Values:
  • Restart = 0 - The tween restarts from the beginning after reaching the end.

  • Yoyo = 1 - The tween reverses direction and plays backward after reaching the end.

Structures

TweenSeq

Sequence of tweens

Fields:
  • items : array< TweenSeqItem > - List of items in the sequence

  • onComplete : lambda<void> - Callback called when the sequence is completed

  • cursor : int - current item index

Classes

Tween
Fields:
  • target : NodeId - Assigned node

  • duration : float = 1f - Duration of the tween in seconds

  • loopType : LoopType = tween::LoopType.Yoyo - Looping behavior

  • loops : int = 0 - Loops count, 0 - no loops, negative value - infinite

  • easing : function<(arg:float):float> - Easing function

  • onComplete : lambda<void> - Callback called when the tween is completed

Functions

linear_f1(arg: float): float

linear easing function. Default easing for tweens.

Arguments:
  • arg : float

create_tween(target: NodeId; from: function<(target:NodeId):float>; to: float; set: function<(target:NodeId;v:float):void>; duration: float; easing: function<(value:float):float> = @@linear_f1): Tween?

create a basic tween, automatically starts it or add it to a sequence with @@next

Arguments:
  • target : NodeId

  • from : function<(target: NodeId ):float>

  • to : float

  • set : function<(target: NodeId ;v:float):void>

  • duration : float

  • easing : function<(value:float):float>

create_tween(target: NodeId; from: float; to: float; set: function<(target:NodeId;v:float):void>; duration: float; easing: function<(value:float):float> = @@linear_f1): Tween?

create a basic tween, automatically starts it or add it to a sequence with @@next

Arguments:
  • target : NodeId

  • from : float

  • to : float

  • set : function<(target: NodeId ;v:float):void>

  • duration : float

  • easing : function<(value:float):float>

create_tween(target: NodeId; from: function<(target:NodeId):float2>; to: float2; set: function<(target:NodeId;v:float2):void>; duration: float; easing: function<(value:float):float> = @@linear_f1): Tween?

create a basic tween, automatically starts it or add it to a sequence with @@next

Arguments:
  • target : NodeId

  • from : function<(target: NodeId ):float2>

  • to : float2

  • set : function<(target: NodeId ;v:float2):void>

  • duration : float

  • easing : function<(value:float):float>

create_tween(target: NodeId; from: float2; to: float2; set: function<(target:NodeId;v:float2):void>; duration: float; easing: function<(value:float):float> = @@linear_f1): Tween?

create a basic tween, automatically starts it or add it to a sequence with @@next

Arguments:
  • target : NodeId

  • from : float2

  • to : float2

  • set : function<(target: NodeId ;v:float2):void>

  • duration : float

  • easing : function<(value:float):float>

create_tween(target: NodeId; from: function<(target:NodeId):float3>; to: float3; set: function<(target:NodeId;v:float3):void>; duration: float; easing: function<(value:float):float> = @@linear_f1): Tween?

create a basic tween, automatically starts it or add it to a sequence with @@next

Arguments:
  • target : NodeId

  • from : function<(target: NodeId ):float3>

  • to : float3

  • set : function<(target: NodeId ;v:float3):void>

  • duration : float

  • easing : function<(value:float):float>

create_tween(target: NodeId; from: float3; to: float3; set: function<(target:NodeId;v:float3):void>; duration: float; easing: function<(value:float):float> = @@linear_f1): Tween?

create a basic tween, automatically starts it or add it to a sequence with @@next

Arguments:
  • target : NodeId

  • from : float3

  • to : float3

  • set : function<(target: NodeId ;v:float3):void>

  • duration : float

  • easing : function<(value:float):float>

create_tween(target: NodeId; from: function<(target:NodeId):float4>; to: float4; set: function<(target:NodeId;v:float4):void>; duration: float; easing: function<(value:float):float> = @@linear_f1): Tween?

create a basic tween, automatically starts it or add it to a sequence with @@next

Arguments:
  • target : NodeId

  • from : function<(target: NodeId ):float4>

  • to : float4

  • set : function<(target: NodeId ;v:float4):void>

  • duration : float

  • easing : function<(value:float):float>

create_tween(target: NodeId; from: float4; to: float4; set: function<(target:NodeId;v:float4):void>; duration: float; easing: function<(value:float):float> = @@linear_f1): Tween?

create a basic tween, automatically starts it or add it to a sequence with @@next

Arguments:
  • target : NodeId

  • from : float4

  • to : float4

  • set : function<(target: NodeId ;v:float4):void>

  • duration : float

  • easing : function<(value:float):float>

set_easing(tween: Tween?; easing: function<(value:float):float> = @@linear_f1): Tween?

set the easing function for a tween

Arguments:
  • tween : Tween ?

  • easing : function<(value:float):float>

set_loops(tween: Tween?; loops: int; loopType: LoopType = tween::LoopType.Restart): Tween?

set the number of loops for a tween (-1 = infinite)

Arguments:
on_complete(t: Tween?; f: lambda<():void>): Tween?

set the onComplete callback for a tween

Arguments:
  • t : Tween ?

  • f : lambda<void>

complete_tween(t: Tween?)

complete a tween, does not call onComplete

Arguments:
kill_tween(t: Tween?): bool

kill a tween. Immediately stops the tween execution, does not call onComplete

Arguments:
scale_tween(target: NodeId; to: float3; duration: float; easing: function<(value:float):float> = @@linear_f1): Tween?

create a tween to scale a node, uses the current scale of the node, usefull for sequenced tweens

Arguments:
  • target : NodeId

  • to : float3

  • duration : float

  • easing : function<(value:float):float>

scale_tween(target: NodeId; to: float; duration: float; easing: function<(value:float):float> = @@linear_f1): Tween?

create a tween to scale a node, uses the current scale of the node, usefull for sequenced tweens

Arguments:
  • target : NodeId

  • to : float

  • duration : float

  • easing : function<(value:float):float>

scale_tween(target: NodeId; from: float3; to: float3; duration: float; easing: function<(value:float):float> = @@linear_f1): Tween?

create a tween to scale a node

Arguments:
  • target : NodeId

  • from : float3

  • to : float3

  • duration : float

  • easing : function<(value:float):float>

scale_tween(target: NodeId; from: float; to: float; duration: float; easing: function<(value:float):float> = @@linear_f1): Tween?

create a tween to scale a node

Arguments:
  • target : NodeId

  • from : float

  • to : float

  • duration : float

  • easing : function<(value:float):float>

position_tween(target: NodeId; to: float3; duration: float; easing: function<(value:float):float> = @@linear_f1): Tween?

create a tween to move a node, read the current position of the node, usefull for sequenced tweens

Arguments:
  • target : NodeId

  • to : float3

  • duration : float

  • easing : function<(value:float):float>

position_tween(target: NodeId; from: float3; to: float3; duration: float; easing: function<(value:float):float> = @@linear_f1): Tween?

create a tween to move a node

Arguments:
  • target : NodeId

  • from : float3

  • to : float3

  • duration : float

  • easing : function<(value:float):float>

rotation_tween(target: NodeId; to: float3; duration: float; easing: function<(value:float):float> = @@linear_f1): Tween?

create a tween to rotate a node, read the current rotation of the node, usefull for sequenced tweens euler angles in radians

Arguments:
  • target : NodeId

  • to : float3

  • duration : float

  • easing : function<(value:float):float>

rotation_tween(target: NodeId; from: float3; to: float3; duration: float; easing: function<(value:float):float> = @@linear_f1): Tween?

create a tween to rotate a node euler angles in radians

Arguments:
  • target : NodeId

  • from : float3

  • to : float3

  • duration : float

  • easing : function<(value:float):float>

rotation_tween_degrees(target: NodeId; to: float3; duration: float; easing: function<(value:float):float> = @@linear_f1): Tween?

create a tween to rotate a node rotation is in degrees

Arguments:
  • target : NodeId

  • to : float3

  • duration : float

  • easing : function<(value:float):float>

rotation_tween_degrees(target: NodeId; from: float3; to: float3; duration: float; easing: function<(value:float):float> = @@linear_f1): Tween?

create a tween to rotate a node rotation is in degrees

Arguments:
  • target : NodeId

  • from : float3

  • to : float3

  • duration : float

  • easing : function<(value:float):float>

active_tween(target: NodeId; active: bool; duration: float; easing: function<(value:float):float> = @@linear_f1): Tween?

create a tween to activate/deactivate a node, read the current active state of the node, usefull for sequenced tweens

Arguments:
  • target : NodeId

  • active : bool

  • duration : float

  • easing : function<(value:float):float>

active_tween(target: NodeId; from: bool; to: bool; duration: float; easing: function<(value:float):float> = @@linear_f1): Tween?

create a tween to activate/deactivate a node

Arguments:
  • target : NodeId

  • from : bool

  • to : bool

  • duration : float

  • easing : function<(value:float):float>

create_tween_seq(): TweenSeq?

create a sequence of tweens, tween sequences can be nested. Sequences are automatically started.

add_start_delay(seq: TweenSeq?; delay: float): TweenSeq?

add a delay to the beginning of a sequence

Arguments:
next(seq: TweenSeq?; tween: Tween?; delay: float = 0f): TweenSeq?

add a tween to a sequence, it will be run after the last tween added to the sequence

Arguments:
next(seq: TweenSeq?; sub: TweenSeq?; delay: float = 0f): TweenSeq?

add a tween to a sequence, it will be run after the last tween added to the sequence

Arguments:
add_delay(seq: TweenSeq?; delay: float): TweenSeq?

add a delay to a sequence, next added tween will be run after the delay

Arguments:
join(seq: TweenSeq?; tween: Tween?): TweenSeq?

join a tween to a sequence, it will be run in parallel with the last tween added to the sequence

Arguments:
join(seq: TweenSeq?; sub: TweenSeq?): TweenSeq?

join a tween to a sequence, it will be run in parallel with the last tween added to the sequence

Arguments:
on_step_complete(t: TweenSeq?; f: lambda<():void>): TweenSeq?

add a callback to a sequence, it will be run called the last tween added to the sequence is completed. It’s useful to chain sequences to catch the moment when the required subsequence is completed.

Arguments:
on_complete(t: TweenSeq?; f: lambda<():void>): TweenSeq?

set the onComplete callback for a sequence

Arguments:
complete_tween(seq: TweenSeq?)

complete a sequence, does not call onComplete

Arguments:
kill_tween(seq: TweenSeq?): bool

kill a sequence. Immediately stops execution, does not call onComplete

Arguments:
has_target(tween: Tween?; target: NodeId): bool

check if a tween is assigned to a node

Arguments:
has_target(seq: TweenSeq?; target: NodeId): bool

check if a sequence has a tween assigned to a node

Arguments:
kill_tweens(target: NodeId): int

kill all tweens assigned to a node

Arguments:
kill_tweens(target: Component?): int

kill all tweens assigned to a component related to a node

Arguments:
complete_tweens(target: NodeId): int

complete all tweens assigned to a node, does not call onComplete

Arguments:
complete_tweens(target: Component?): int

complete all tweens assigned to a component related to a node, does not call onComplete

Arguments: