.. _stdlib_tween: ===== 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 ++++++++++++ .. _enum-tween-LoopType: .. das:attribute:: 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 ++++++++++ .. _struct-tween-TweenSeq: .. das:attribute:: TweenSeq Sequence of tweens :Fields: * **items** : array< :ref:`TweenSeqItem ` > - List of items in the sequence * **onComplete** : lambda - Callback called when the sequence is completed * **cursor** : int - current item index +++++++ Classes +++++++ .. _struct-tween-Tween: .. das:attribute:: Tween :Fields: * **target** : :ref:`NodeId ` - Assigned node * **duration** : float = 1f - Duration of the tween in seconds * **loopType** : :ref:`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 - Callback called when the tween is completed +++++++++ Functions +++++++++ * :ref:`linear_f1 (arg: float) : float ` * :ref:`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? ` * :ref:`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? ` * :ref:`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? ` * :ref:`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? ` * :ref:`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? ` * :ref:`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? ` * :ref:`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? ` * :ref:`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? ` * :ref:`set_easing (var tween: Tween?; var easing: function\<(value:float):float\> = @@linear_f1) : Tween? ` * :ref:`set_loops (var tween: Tween?; loops: int; loopType: LoopType = tween::LoopType.Restart) : Tween? ` * :ref:`on_complete (var t: Tween?; var f: lambda\<():void\>) : Tween? ` * :ref:`complete_tween (var t: Tween?) ` * :ref:`kill_tween (var t: Tween?) : bool ` * :ref:`scale_tween (target: NodeId; to: float3; duration: float; easing: function\<(value:float):float\> = @@linear_f1) : Tween? ` * :ref:`scale_tween (target: NodeId; to: float; duration: float; easing: function\<(value:float):float\> = @@linear_f1) : Tween? ` * :ref:`scale_tween (target: NodeId; from: float3; to: float3; duration: float; easing: function\<(value:float):float\> = @@linear_f1) : Tween? ` * :ref:`scale_tween (target: NodeId; from: float; to: float; duration: float; easing: function\<(value:float):float\> = @@linear_f1) : Tween? ` * :ref:`position_tween (target: NodeId; to: float3; duration: float; easing: function\<(value:float):float\> = @@linear_f1) : Tween? ` * :ref:`position_tween (target: NodeId; from: float3; to: float3; duration: float; easing: function\<(value:float):float\> = @@linear_f1) : Tween? ` * :ref:`rotation_tween (target: NodeId; to: float3; duration: float; easing: function\<(value:float):float\> = @@linear_f1) : Tween? ` * :ref:`rotation_tween (target: NodeId; from: float3; to: float3; duration: float; easing: function\<(value:float):float\> = @@linear_f1) : Tween? ` * :ref:`rotation_tween_degrees (target: NodeId; to: float3; duration: float; easing: function\<(value:float):float\> = @@linear_f1) : Tween? ` * :ref:`rotation_tween_degrees (target: NodeId; from: float3; to: float3; duration: float; easing: function\<(value:float):float\> = @@linear_f1) : Tween? ` * :ref:`active_tween (target: NodeId; active: bool; duration: float; easing: function\<(value:float):float\> = @@linear_f1) : Tween? ` * :ref:`active_tween (target: NodeId; from: bool; to: bool; duration: float; easing: function\<(value:float):float\> = @@linear_f1) : Tween? ` * :ref:`create_tween_seq () : TweenSeq? ` * :ref:`add_start_delay (var seq: TweenSeq?; delay: float) : TweenSeq? ` * :ref:`next (var seq: TweenSeq?; var tween: Tween?; delay: float = 0f) : TweenSeq? ` * :ref:`next (var seq: TweenSeq?; var sub: TweenSeq?; delay: float = 0f) : TweenSeq? ` * :ref:`add_delay (var seq: TweenSeq?; delay: float) : TweenSeq? ` * :ref:`join (var seq: TweenSeq?; var tween: Tween?) : TweenSeq? ` * :ref:`join (var seq: TweenSeq?; var sub: TweenSeq?) : TweenSeq? ` * :ref:`on_step_complete (var t: TweenSeq?; var f: lambda\<():void\>) : TweenSeq? ` * :ref:`on_complete (var t: TweenSeq?; var f: lambda\<():void\>) : TweenSeq? ` * :ref:`complete_tween (var seq: TweenSeq?) ` * :ref:`kill_tween (var seq: TweenSeq?) : bool ` * :ref:`has_target (var tween: Tween?; target: NodeId) : bool ` * :ref:`has_target (var seq: TweenSeq?; target: NodeId) : bool ` * :ref:`kill_tweens (target: NodeId) : int ` * :ref:`kill_tweens (target: Component?) : int ` * :ref:`complete_tweens (target: NodeId) : int ` * :ref:`complete_tweens (target: Component?) : int ` .. _function-tween_linear_f1_float: .. das:function:: linear_f1(arg: float) : float linear easing function. Default easing for tweens. :Arguments: * **arg** : float .. _function-tween_create_tween_NodeId_function_ls_target_c_NodeId_c_float_gr__float_function_ls_target_c_NodeId;v_c_float_c_void_gr__float_function_ls_value_c_float_c_float_gr_: .. das:function:: 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** : :ref:`NodeId ` * **from** : function<(target: :ref:`NodeId ` ):float> * **to** : float * **set** : function<(target: :ref:`NodeId ` ;v:float):void> * **duration** : float * **easing** : function<(value:float):float> .. _function-tween_create_tween_NodeId_float_float_function_ls_target_c_NodeId;v_c_float_c_void_gr__float_function_ls_value_c_float_c_float_gr_: .. das:function:: 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** : :ref:`NodeId ` * **from** : float * **to** : float * **set** : function<(target: :ref:`NodeId ` ;v:float):void> * **duration** : float * **easing** : function<(value:float):float> .. _function-tween_create_tween_NodeId_function_ls_target_c_NodeId_c_float2_gr__float2_function_ls_target_c_NodeId;v_c_float2_c_void_gr__float_function_ls_value_c_float_c_float_gr_: .. das:function:: 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** : :ref:`NodeId ` * **from** : function<(target: :ref:`NodeId ` ):float2> * **to** : float2 * **set** : function<(target: :ref:`NodeId ` ;v:float2):void> * **duration** : float * **easing** : function<(value:float):float> .. _function-tween_create_tween_NodeId_float2_float2_function_ls_target_c_NodeId;v_c_float2_c_void_gr__float_function_ls_value_c_float_c_float_gr_: .. das:function:: 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** : :ref:`NodeId ` * **from** : float2 * **to** : float2 * **set** : function<(target: :ref:`NodeId ` ;v:float2):void> * **duration** : float * **easing** : function<(value:float):float> .. _function-tween_create_tween_NodeId_function_ls_target_c_NodeId_c_float3_gr__float3_function_ls_target_c_NodeId;v_c_float3_c_void_gr__float_function_ls_value_c_float_c_float_gr_: .. das:function:: 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** : :ref:`NodeId ` * **from** : function<(target: :ref:`NodeId ` ):float3> * **to** : float3 * **set** : function<(target: :ref:`NodeId ` ;v:float3):void> * **duration** : float * **easing** : function<(value:float):float> .. _function-tween_create_tween_NodeId_float3_float3_function_ls_target_c_NodeId;v_c_float3_c_void_gr__float_function_ls_value_c_float_c_float_gr_: .. das:function:: 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** : :ref:`NodeId ` * **from** : float3 * **to** : float3 * **set** : function<(target: :ref:`NodeId ` ;v:float3):void> * **duration** : float * **easing** : function<(value:float):float> .. _function-tween_create_tween_NodeId_function_ls_target_c_NodeId_c_float4_gr__float4_function_ls_target_c_NodeId;v_c_float4_c_void_gr__float_function_ls_value_c_float_c_float_gr_: .. das:function:: 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** : :ref:`NodeId ` * **from** : function<(target: :ref:`NodeId ` ):float4> * **to** : float4 * **set** : function<(target: :ref:`NodeId ` ;v:float4):void> * **duration** : float * **easing** : function<(value:float):float> .. _function-tween_create_tween_NodeId_float4_float4_function_ls_target_c_NodeId;v_c_float4_c_void_gr__float_function_ls_value_c_float_c_float_gr_: .. das:function:: 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** : :ref:`NodeId ` * **from** : float4 * **to** : float4 * **set** : function<(target: :ref:`NodeId ` ;v:float4):void> * **duration** : float * **easing** : function<(value:float):float> .. _function-tween_set_easing_Tween_q__function_ls_value_c_float_c_float_gr_: .. das:function:: set_easing(tween: Tween?; easing: function<(value:float):float> = @@linear_f1) : Tween? set the easing function for a tween :Arguments: * **tween** : :ref:`Tween ` ? * **easing** : function<(value:float):float> .. _function-tween_set_loops_Tween_q__int_LoopType: .. das:function:: set_loops(tween: Tween?; loops: int; loopType: LoopType = tween::LoopType.Restart) : Tween? set the number of loops for a tween (-1 = infinite) :Arguments: * **tween** : :ref:`Tween ` ? * **loops** : int * **loopType** : :ref:`LoopType ` .. _function-tween_on_complete_Tween_q__lambda_ls__c_void_gr_: .. das:function:: on_complete(t: Tween?; f: lambda<():void>) : Tween? set the onComplete callback for a tween :Arguments: * **t** : :ref:`Tween ` ? * **f** : lambda .. _function-tween_complete_tween_Tween_q_: .. das:function:: complete_tween(t: Tween?) complete a tween, does not call onComplete :Arguments: * **t** : :ref:`Tween ` ? .. _function-tween_kill_tween_Tween_q_: .. das:function:: kill_tween(t: Tween?) : bool kill a tween. Immediately stops the tween execution, does not call onComplete :Arguments: * **t** : :ref:`Tween ` ? .. _function-tween_scale_tween_NodeId_float3_float_function_ls_value_c_float_c_float_gr_: .. das:function:: 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** : :ref:`NodeId ` * **to** : float3 * **duration** : float * **easing** : function<(value:float):float> .. _function-tween_scale_tween_NodeId_float_float_function_ls_value_c_float_c_float_gr_: .. das:function:: 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** : :ref:`NodeId ` * **to** : float * **duration** : float * **easing** : function<(value:float):float> .. _function-tween_scale_tween_NodeId_float3_float3_float_function_ls_value_c_float_c_float_gr_: .. das:function:: 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** : :ref:`NodeId ` * **from** : float3 * **to** : float3 * **duration** : float * **easing** : function<(value:float):float> .. _function-tween_scale_tween_NodeId_float_float_float_function_ls_value_c_float_c_float_gr_: .. das:function:: 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** : :ref:`NodeId ` * **from** : float * **to** : float * **duration** : float * **easing** : function<(value:float):float> .. _function-tween_position_tween_NodeId_float3_float_function_ls_value_c_float_c_float_gr_: .. das:function:: 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** : :ref:`NodeId ` * **to** : float3 * **duration** : float * **easing** : function<(value:float):float> .. _function-tween_position_tween_NodeId_float3_float3_float_function_ls_value_c_float_c_float_gr_: .. das:function:: 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** : :ref:`NodeId ` * **from** : float3 * **to** : float3 * **duration** : float * **easing** : function<(value:float):float> .. _function-tween_rotation_tween_NodeId_float3_float_function_ls_value_c_float_c_float_gr_: .. das:function:: 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** : :ref:`NodeId ` * **to** : float3 * **duration** : float * **easing** : function<(value:float):float> .. _function-tween_rotation_tween_NodeId_float3_float3_float_function_ls_value_c_float_c_float_gr_: .. das:function:: 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** : :ref:`NodeId ` * **from** : float3 * **to** : float3 * **duration** : float * **easing** : function<(value:float):float> .. _function-tween_rotation_tween_degrees_NodeId_float3_float_function_ls_value_c_float_c_float_gr_: .. das:function:: 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** : :ref:`NodeId ` * **to** : float3 * **duration** : float * **easing** : function<(value:float):float> .. _function-tween_rotation_tween_degrees_NodeId_float3_float3_float_function_ls_value_c_float_c_float_gr_: .. das:function:: 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** : :ref:`NodeId ` * **from** : float3 * **to** : float3 * **duration** : float * **easing** : function<(value:float):float> .. _function-tween_active_tween_NodeId_bool_float_function_ls_value_c_float_c_float_gr_: .. das:function:: 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** : :ref:`NodeId ` * **active** : bool * **duration** : float * **easing** : function<(value:float):float> .. _function-tween_active_tween_NodeId_bool_bool_float_function_ls_value_c_float_c_float_gr_: .. das:function:: 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** : :ref:`NodeId ` * **from** : bool * **to** : bool * **duration** : float * **easing** : function<(value:float):float> .. _function-tween_create_tween_seq: .. das:function:: create_tween_seq() : TweenSeq? create a sequence of tweens, tween sequences can be nested. Sequences are automatically started. .. _function-tween_add_start_delay_TweenSeq_q__float: .. das:function:: add_start_delay(seq: TweenSeq?; delay: float) : TweenSeq? add a delay to the beginning of a sequence :Arguments: * **seq** : :ref:`TweenSeq ` ? * **delay** : float .. _function-tween_next_TweenSeq_q__Tween_q__float: .. das:function:: 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: * **seq** : :ref:`TweenSeq ` ? * **tween** : :ref:`Tween ` ? * **delay** : float .. _function-tween_next_TweenSeq_q__TweenSeq_q__float: .. das:function:: 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: * **seq** : :ref:`TweenSeq ` ? * **sub** : :ref:`TweenSeq ` ? * **delay** : float .. _function-tween_add_delay_TweenSeq_q__float: .. das:function:: add_delay(seq: TweenSeq?; delay: float) : TweenSeq? add a delay to a sequence, next added tween will be run after the delay :Arguments: * **seq** : :ref:`TweenSeq ` ? * **delay** : float .. _function-tween_join_TweenSeq_q__Tween_q_: .. das:function:: 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: * **seq** : :ref:`TweenSeq ` ? * **tween** : :ref:`Tween ` ? .. _function-tween_join_TweenSeq_q__TweenSeq_q_: .. das:function:: 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: * **seq** : :ref:`TweenSeq ` ? * **sub** : :ref:`TweenSeq ` ? .. _function-tween_on_step_complete_TweenSeq_q__lambda_ls__c_void_gr_: .. das:function:: 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: * **t** : :ref:`TweenSeq ` ? * **f** : lambda .. _function-tween_on_complete_TweenSeq_q__lambda_ls__c_void_gr_: .. das:function:: on_complete(t: TweenSeq?; f: lambda<():void>) : TweenSeq? set the onComplete callback for a sequence :Arguments: * **t** : :ref:`TweenSeq ` ? * **f** : lambda .. _function-tween_complete_tween_TweenSeq_q_: .. das:function:: complete_tween(seq: TweenSeq?) complete a sequence, does not call onComplete :Arguments: * **seq** : :ref:`TweenSeq ` ? .. _function-tween_kill_tween_TweenSeq_q_: .. das:function:: kill_tween(seq: TweenSeq?) : bool kill a sequence. Immediately stops execution, does not call onComplete :Arguments: * **seq** : :ref:`TweenSeq ` ? .. _function-tween_has_target_Tween_q__NodeId: .. das:function:: has_target(tween: Tween?; target: NodeId) : bool check if a tween is assigned to a node :Arguments: * **tween** : :ref:`Tween ` ? * **target** : :ref:`NodeId ` .. _function-tween_has_target_TweenSeq_q__NodeId: .. das:function:: has_target(seq: TweenSeq?; target: NodeId) : bool check if a sequence has a tween assigned to a node :Arguments: * **seq** : :ref:`TweenSeq ` ? * **target** : :ref:`NodeId ` .. _function-tween_kill_tweens_NodeId: .. das:function:: kill_tweens(target: NodeId) : int kill all tweens assigned to a node :Arguments: * **target** : :ref:`NodeId ` .. _function-tween_kill_tweens_Component_q_: .. das:function:: kill_tweens(target: Component?) : int kill all tweens assigned to a component related to a node :Arguments: * **target** : :ref:`Component ` ? .. _function-tween_complete_tweens_NodeId: .. das:function:: complete_tweens(target: NodeId) : int complete all tweens assigned to a node, does not call onComplete :Arguments: * **target** : :ref:`NodeId ` .. _function-tween_complete_tweens_Component_q_: .. das:function:: complete_tweens(target: Component?) : int complete all tweens assigned to a component related to a node, does not call onComplete :Arguments: * **target** : :ref:`Component ` ?