Tween¶
Anima suavemente las propiedades de un nodo a lo largo del tiempo.
Descripción¶
Tweens are useful for animations requiring a numerical property to be interpolated over a range of values. The name tween comes from in-betweening, an animation technique where you specify keyframes and the computer interpolates the frames that appear between them.
Tween
is more suited than AnimationPlayer for animations where you don't know the final values in advance. For example, interpolating a dynamically-chosen camera zoom value is best done with a Tween
node; it would be difficult to do the same thing with an AnimationPlayer node.
Here is a brief usage example that makes a 2D node move smoothly between two positions:
var tween = get_node("Tween")
tween.interpolate_property($Node2D, "position",
Vector2(0, 0), Vector2(100, 100), 1,
Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
tween.start()
Many methods require a property name, such as "position"
above. You can find the correct property name by hovering over the property in the Inspector. You can also provide the components of a property directly by using "property:component"
(e.g. position:x
), where it would only apply to that particular component.
Many of the methods accept trans_type
and ease_type
. The first accepts an TransitionType constant, and refers to the way the timing of the animation is handled (see easings.net for some examples). The second accepts an EaseType constant, and controls where the trans_type
is applied to the interpolation (in the beginning, the end, or both). If you don't know which transition and easing to pick, you can try different TransitionType constants with EASE_IN_OUT, and use the one that looks best.
Propiedades¶
|
||
|
||
|
Métodos¶
follow_method ( Object object, String method, Variant initial_val, Object target, String target_method, float duration, TransitionType trans_type=0, EaseType ease_type=2, float delay=0 ) |
|
follow_property ( Object object, NodePath property, Variant initial_val, Object target, NodePath target_property, float duration, TransitionType trans_type=0, EaseType ease_type=2, float delay=0 ) |
|
get_runtime ( ) const |
|
interpolate_callback ( Object object, float duration, String callback, Variant arg1=null, Variant arg2=null, Variant arg3=null, Variant arg4=null, Variant arg5=null ) |
|
interpolate_deferred_callback ( Object object, float duration, String callback, Variant arg1=null, Variant arg2=null, Variant arg3=null, Variant arg4=null, Variant arg5=null ) |
|
interpolate_method ( Object object, String method, Variant initial_val, Variant final_val, float duration, TransitionType trans_type=0, EaseType ease_type=2, float delay=0 ) |
|
interpolate_property ( Object object, NodePath property, Variant initial_val, Variant final_val, float duration, TransitionType trans_type=0, EaseType ease_type=2, float delay=0 ) |
|
is_active ( ) const |
|
remove_all ( ) |
|
reset_all ( ) |
|
resume_all ( ) |
|
void |
set_active ( bool active ) |
start ( ) |
|
stop_all ( ) |
|
targeting_method ( Object object, String method, Object initial, String initial_method, Variant final_val, float duration, TransitionType trans_type=0, EaseType ease_type=2, float delay=0 ) |
|
targeting_property ( Object object, NodePath property, Object initial, NodePath initial_val, Variant final_val, float duration, TransitionType trans_type=0, EaseType ease_type=2, float delay=0 ) |
|
tell ( ) const |
Señales¶
tween_all_completed ( )
Emitido cuando todos los procesos en un tween terminan.
Emitido cuando un tween termina.
Emitido cuando empieza un tween.
Emitido en cada paso de la animación.
Enumeraciones¶
enum TweenProcessMode:
TWEEN_PROCESS_PHYSICS = 0 --- El tween se actualiza con la llamada de
_physics_process
.TWEEN_PROCESS_IDLE = 1 --- El tween se actualiza con la llamada de
_process
.
enum TransitionType:
TRANS_LINEAR = 0 --- La animación se interpola linealmente.
TRANS_SINE = 1 --- La animación se interpola usando una función senoidal.
TRANS_QUINT = 2 --- La animación se interpola con una función a la quinta (a la potencia de 5).
TRANS_QUART = 3 --- La animación se interpola con una función a la cuarta (a la potencia de 4).
TRANS_QUAD = 4 --- La animación se interpola con una función cuadrática (a la potencia de 2).
TRANS_EXPO = 5 --- La animación se interpola con una función exponencial (a la potencia de x).
TRANS_ELASTIC = 6 --- La animación se interpola con elasticidad, moviéndose alrededor de los bordes.
TRANS_CUBIC = 7 --- La animación se interpola con una función cúbica (a la potencia de 3).
TRANS_CIRC = 8 --- La animación se interpola con una función que utiliza raíces cuadradas.
TRANS_BOUNCE = 9 --- La animación se interpola al rebotar al final.
TRANS_BACK = 10 --- La animación es interpolada retrocediendo en los extremos.
enum EaseType:
EASE_IN = 0 --- La interpolación comienza lentamente y se acelera hacia el final.
EASE_OUT = 1 --- La interpolación comienza rápidamente y se ralentiza hacia el final.
EASE_IN_OUT = 2 --- Una combinación de EASE_IN y EASE_OUT. La interpolación es más lenta en ambos extremos.
EASE_OUT_IN = 3 --- Una combinación de EASE_IN y EASE_OUT. La interpolación es más rápida en ambos extremos.
Descripciones de Propiedades¶
TweenProcessMode playback_process_mode
Default |
|
Setter |
set_tween_process_mode(value) |
Getter |
get_tween_process_mode() |
El hilo del proceso de animación del tween. Ver TweenProcessMode.
float playback_speed
Default |
|
Setter |
set_speed_scale(value) |
Getter |
get_speed_scale() |
El multiplicador de velocidad del tween. Por ejemplo, ponlo en 1.0
para la velocidad normal, 2.0
para dos veces la velocidad normal, o 0.5
para la mitad de la velocidad normal. Un valor de 0
pausa la animación, pero también ver set_active o stop_all para esto.
bool repeat
Default |
|
Setter |
set_repeat(value) |
Getter |
is_repeat() |
Si true
, el tween realiza un bucle.
Descripciones de Métodos¶
bool follow_method ( Object object, String method, Variant initial_val, Object target, String target_method, float duration, TransitionType trans_type=0, EaseType ease_type=2, float delay=0 )
Sigue el method
de object
y aplica el valor devuelto en target_method
de target
, empezando por initial_val
durante duration
segundos, delay
más tarde. Los métodos se llaman con valores consecutivos.
Utilice TransitionType para los parámetros de trans_type
y EaseType para los parámetros de ease_type
. Estos valores controlan el tiempo y la dirección de la interpolación. Vea la descripción de la clase para más información.
bool follow_property ( Object object, NodePath property, Variant initial_val, Object target, NodePath target_property, float duration, TransitionType trans_type=0, EaseType ease_type=2, float delay=0 )
Sigue la property
de object
y la aplica sobre target_property
de target
, empezando por initial_val
durante duration
segundos, delay
segundos después.
Utilice TransitionType para los parámetros de trans_type
y EaseType para los parámetros de ease_type
. Estos valores controlan el tiempo y la dirección de la interpolación. Vea la descripción de la clase para más información.
float get_runtime ( ) const
Devuelve el tiempo total necesario para que todos los tweens terminen. Si tienes dos tweens, uno que dura 10 segundos y el otro 20 segundos, devolvería 20 segundos, ya que para entonces todos los tweens habrían terminado.
bool interpolate_callback ( Object object, float duration, String callback, Variant arg1=null, Variant arg2=null, Variant arg3=null, Variant arg4=null, Variant arg5=null )
Llama a callback
de object
después de duration
. arg1
-arg5
son argumentos que se pasan a la devolución de llamada.
bool interpolate_deferred_callback ( Object object, float duration, String callback, Variant arg1=null, Variant arg2=null, Variant arg3=null, Variant arg4=null, Variant arg5=null )
Llama a callback
de object
después de duration
. arg1
-arg5
son argumentos que se pasan a la devolución de llamada.
bool interpolate_method ( Object object, String method, Variant initial_val, Variant final_val, float duration, TransitionType trans_type=0, EaseType ease_type=2, float delay=0 )
Anima el method
de object
desde initial_val
hasta final_val
durante duración
segundos, delay
segundos más tarde. Los métodos se llaman con valores consecutivos.
Use TransitionType para trans_type
y EaseType para los parámetros de ease_type
. Estos valores controlan el tiempo y la dirección de la interpolación. Vea la descripción de la clase para más información.
bool interpolate_property ( Object object, NodePath property, Variant initial_val, Variant final_val, float duration, TransitionType trans_type=0, EaseType ease_type=2, float delay=0 )
Anima la property
del object
desde initial_val
hasta final_val
durante duration
segundos, delay
segundos más tarde. Al fijar el valor inicial en null
se utiliza el valor actual de la propiedad.
Utilice TransitionType para los parámetros de trans_type
y EaseType para los parámetros de ease_type
. Estos valores controlan el tiempo y la dirección de la interpolación. Vea la descripción de la clase para más información.
bool is_active ( ) const
Devuelve true
si algún tweens se está ejecutando actualmente.
Nota: Este método no considera a los tweens que han terminado.
Detiene la animación y elimina un "tween", dado su objeto y su par propiedad/método. Por defecto, se eliminan todos los tweens, a menos que se especifique key
.
bool remove_all ( )
Detiene la animación y elimina a todos los tweens.
Restablece un tween a su valor inicial (el dado, no el anterior al tween), dada su objeto y su par propiedad/método. Por defecto, se eliminan todos los tweens, a menos que se especifique key
.
bool reset_all ( )
Restablece todos los tweens a sus valores iniciales (los dados, no los anteriores al tween).
Continúa animando a un tween detenido, dada su objeto y par propiedad/método. Por defecto, todos los tweens se reanudan, a menos que se especifique key
.
bool resume_all ( )
Continúa animando a todos los tweens detenidos.
Establece la interpolación al time
dado en segundos.
void set_active ( bool active )
Activa/desactiva el tween. Ver también stop_all y resume_all.
bool start ( )
Empieza el tween. Puedes definir animaciones tanto antes como después de esto.
Detiene un tween, dado su objeto y su par de propiedades/métodos. Por defecto, todos los tweens se detienen, a menos que se especifique key
.
bool stop_all ( )
Para de animar a todos los tweens.
bool targeting_method ( Object object, String method, Object initial, String initial_method, Variant final_val, float duration, TransitionType trans_type=0, EaseType ease_type=2, float delay=0 )
Anima el method
de object
desde el valor devuelto por initial_method
hasta final_val
durante duration
segundos, delay
segundos más tarde. Los métodos se animan llamándolos con valores consecutivos.
Utilice TransitionType para los parámetros trans_type
y EaseType para los parámetros ease_type
. Estos valores controlan el tiempo y la dirección de la interpolación. Vea la descripción de la clase para más información.
bool targeting_property ( Object object, NodePath property, Object initial, NodePath initial_val, Variant final_val, float duration, TransitionType trans_type=0, EaseType ease_type=2, float delay=0 )
Anima la propiedad property
de object
desde el valor actual de la propiedad initial_val
de initial
hasta final_val
durante duration
segundos, delay
segundos más tarde.
Utilice TransitionType para los parámetros de trans_type
y EaseType para los parámetros de ease_type
. Estos valores controlan el tiempo y la dirección de la interpolación. Vea la descripción de la clase para más información.
float tell ( ) const
Devuelve la tiempo actual del tween.