From 5668cec030e67a89994a97db06ca7101ab9be272 Mon Sep 17 00:00:00 2001 From: sanikoyes Date: Thu, 21 Aug 2014 15:34:16 +0800 Subject: [PATCH] Add tween delay support Add tween get_runtime function Update demo for tween delay sample --- demos/misc/tween/main.gd | 15 ++++++-- demos/misc/tween/main.xml | 11 +++--- scene/animation/tween.cpp | 75 +++++++++++++++++++++++++++++++-------- scene/animation/tween.h | 5 +++ 4 files changed, 84 insertions(+), 22 deletions(-) diff --git a/demos/misc/tween/main.gd b/demos/misc/tween/main.gd index 5f6828f6f41..002e720e793 100644 --- a/demos/misc/tween/main.gd +++ b/demos/misc/tween/main.gd @@ -89,17 +89,21 @@ func reset_tween(): if get_node("modes/move").is_pressed(): tween.interpolate_method(sprite, "set_pos", Vector2(0,0), Vector2(736, 184), 2, state.trans, state.eases) + tween.interpolate_method(sprite, "set_pos", Vector2(736,184), Vector2(0, 0), 2, state.trans, state.eases, 2) if get_node("modes/color").is_pressed(): tween.interpolate_method(sprite, "set_modulate", get_node("color/color_from").get_color(), get_node("color/color_to").get_color(), 2, state.trans, state.eases) + tween.interpolate_method(sprite, "set_modulate", get_node("color/color_to").get_color(), get_node("color/color_from").get_color(), 2, state.trans, state.eases, 2) else: sprite.set_modulate(Color(1, 1, 1, 1)) if get_node("modes/scale").is_pressed(): tween.interpolate_method(sprite, "set_scale", Vector2(0.5,0.5), Vector2(1.5, 1.5), 2, state.trans, state.eases) + tween.interpolate_method(sprite, "set_scale", Vector2(1.5,1.5), Vector2(0.5, 0.5), 2, state.trans, state.eases, 2) if get_node("modes/rotate").is_pressed(): - tween.interpolate_method(sprite, "set_rot", 0.0, 6.28, 2, state.trans, state.eases) + tween.interpolate_method(sprite, "set_rot", 0, 6.28, 2, state.trans, state.eases) + tween.interpolate_method(sprite, "set_rot", 6.28, 0, 2, state.trans, state.eases, 2) tween.set_repeat(get_node("modes/repeat").is_pressed()) tween.start() @@ -114,7 +118,11 @@ func reset_tween(): func _on_tween_step( object, key, elapsed, value ): var timeline = get_node("timeline") - var ratio = 100 * (elapsed / 2) + + var tween = get_node("tween") + var runtime = tween.get_runtime() + + var ratio = 100 * (elapsed / runtime) timeline.set_value(ratio) @@ -123,5 +131,6 @@ func _on_timeline_value_changed( value ): return var tween = get_node("tween") - tween.seek(2.0 * value / 100) + var runtime = tween.get_runtime() + tween.seek(runtime * value / 100) diff --git a/demos/misc/tween/main.xml b/demos/misc/tween/main.xml index 8c6c9c46394..f403937818e 100644 --- a/demos/misc/tween/main.xml +++ b/demos/misc/tween/main.xml @@ -5,7 +5,7 @@ "names" - + "main" "Control" "_import_path" @@ -84,6 +84,7 @@ "color_to" "tween" "Tween" + "playback/process_mode" "playback/active" "playback/repeat" "playback/speed" @@ -147,11 +148,11 @@ "pixel_snap" False "zoom" - 1.360374 + 1.227738 "use_snap" True "ofs" - -220.639, 36.0825 + -319.009, -56.3619 "snap" 8 @@ -323,9 +324,9 @@ 100 "nodes" - -1, -1, 1, 0, -1, 20, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 7, 4, 8, 5, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 20, 9, 21, 10, 0, 0, 0, 23, 22, -1, 20, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 24, 11, 25, 12, 7, 13, 8, 14, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 3, 17, 8, 18, 8, 19, 2, 0, 1, 0, 27, 26, -1, 27, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 7, 15, 8, 16, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 17, 33, 18, 34, 3, 35, 3, 36, 19, 0, 1, 0, 27, 37, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 20, 7, 15, 8, 11, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 21, 33, 18, 34, 3, 35, 3, 36, 19, 0, 1, 0, 27, 38, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 22, 7, 15, 8, 23, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 24, 33, 18, 34, 3, 35, 3, 36, 19, 0, 1, 0, 27, 39, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 25, 7, 15, 8, 26, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 27, 33, 18, 34, 3, 35, 3, 36, 19, 0, 1, 0, 27, 40, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 28, 7, 15, 8, 29, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 30, 33, 18, 34, 3, 35, 3, 36, 19, 0, 1, 0, 27, 41, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 31, 7, 15, 8, 32, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 33, 33, 18, 34, 3, 35, 3, 36, 19, 0, 1, 0, 27, 42, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 34, 7, 15, 8, 35, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 36, 33, 18, 34, 3, 35, 3, 36, 19, 0, 1, 0, 27, 43, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 37, 7, 15, 8, 38, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 39, 33, 18, 34, 3, 35, 3, 36, 19, 0, 1, 0, 27, 44, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 40, 7, 15, 8, 41, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 42, 33, 18, 34, 3, 35, 3, 36, 19, 0, 1, 0, 27, 45, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 43, 7, 15, 8, 44, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 45, 33, 18, 34, 3, 35, 3, 36, 19, 0, 1, 0, 27, 46, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 46, 7, 15, 8, 47, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 48, 33, 18, 34, 3, 35, 3, 36, 19, 0, 0, 0, 23, 47, -1, 20, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 24, 49, 25, 12, 7, 50, 8, 51, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 3, 17, 8, 18, 8, 19, 2, 0, 13, 0, 27, 48, -1, 27, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 7, 52, 8, 16, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 53, 33, 18, 34, 3, 35, 3, 36, 19, 0, 13, 0, 27, 49, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 20, 7, 52, 8, 11, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 54, 33, 18, 34, 3, 35, 3, 36, 19, 0, 13, 0, 27, 50, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 22, 7, 52, 8, 23, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 55, 33, 18, 34, 3, 35, 3, 36, 19, 0, 13, 0, 27, 51, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 25, 7, 52, 8, 26, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 56, 33, 18, 34, 3, 35, 3, 36, 19, 0, 0, 0, 23, 52, -1, 20, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 24, 40, 25, 12, 7, 57, 8, 58, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 3, 17, 8, 18, 8, 19, 2, 0, 18, 0, 27, 53, -1, 27, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 7, 59, 8, 16, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 60, 33, 18, 34, 3, 35, 3, 36, 19, 0, 18, 0, 27, 54, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 20, 7, 59, 8, 11, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 61, 33, 18, 34, 3, 35, 3, 36, 19, 0, 18, 0, 27, 55, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 22, 7, 59, 8, 23, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 62, 33, 18, 34, 3, 35, 3, 36, 19, 0, 18, 0, 27, 56, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 25, 7, 59, 8, 26, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 63, 33, 18, 34, 3, 35, 3, 36, 19, 0, 18, 0, 27, 57, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 28, 7, 59, 8, 29, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 64, 33, 18, 34, 3, 35, 3, 36, 19, 0, 18, 0, 27, 58, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 31, 7, 59, 8, 32, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 65, 33, 18, 34, 3, 35, 3, 36, 19, 0, 0, 0, 23, 54, -1, 20, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 24, 66, 25, 40, 7, 67, 8, 68, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 3, 17, 8, 18, 8, 19, 2, 0, 25, 0, 60, 59, -1, 30, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 7, 69, 8, 70, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 1, 16, 1, 17, 8, 19, 2, 61, 6, 62, 2, 63, 2, 64, 2, 65, 6, 66, 3, 67, 3, 32, 71, 36, 72, 68, 72, 69, 3, 70, 3, 71, 73, 0, 25, 0, 73, 72, -1, 19, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 74, 7, 69, 8, 75, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 3, 17, 8, 18, 8, 19, 2, 0, 25, 0, 60, 74, -1, 31, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 76, 7, 69, 8, 77, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 1, 16, 1, 17, 8, 19, 2, 61, 6, 62, 2, 63, 2, 64, 2, 65, 6, 66, 3, 67, 3, 32, 78, 36, 72, 68, 72, 69, 3, 70, 3, 71, 73, 0, 25, 0, 73, 75, -1, 19, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 79, 7, 69, 8, 80, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 3, 17, 8, 18, 8, 19, 2, 0, 0, 0, 77, 76, -1, 4, 2, 0, 78, 1, 79, 1, 80, 2, 0, 30, 0, 82, 81, -1, 20, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 24, 81, 25, 81, 7, 82, 8, 83, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 0, 31, 0, 84, 83, -1, 19, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 85, 84, 9, 6, 10, 7, 86, 85, 87, 1, 88, 84, 89, 3, 90, 3, 91, 19, 92, 19, 93, 72, 94, 86, 95, 3, 96, 87, 0, 0, 0, 98, 97, -1, 28, 2, 0, 3, 3, 4, 2, 5, 2, 6, 3, 24, 88, 25, 89, 7, 67, 8, 40, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 19, 2, 61, 6, 62, 90, 63, 2, 64, 6, 65, 2, 66, 3, 67, 3, 99, 72, 100, 3, 0 + -1, -1, 1, 0, -1, 20, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 7, 4, 8, 5, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 20, 9, 21, 10, 0, 0, 0, 23, 22, -1, 20, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 24, 11, 25, 12, 7, 13, 8, 14, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 3, 17, 8, 18, 8, 19, 2, 0, 1, 0, 27, 26, -1, 27, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 7, 15, 8, 16, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 17, 33, 18, 34, 3, 35, 3, 36, 19, 0, 1, 0, 27, 37, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 20, 7, 15, 8, 11, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 21, 33, 18, 34, 3, 35, 3, 36, 19, 0, 1, 0, 27, 38, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 22, 7, 15, 8, 23, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 24, 33, 18, 34, 3, 35, 3, 36, 19, 0, 1, 0, 27, 39, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 25, 7, 15, 8, 26, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 27, 33, 18, 34, 3, 35, 3, 36, 19, 0, 1, 0, 27, 40, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 28, 7, 15, 8, 29, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 30, 33, 18, 34, 3, 35, 3, 36, 19, 0, 1, 0, 27, 41, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 31, 7, 15, 8, 32, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 33, 33, 18, 34, 3, 35, 3, 36, 19, 0, 1, 0, 27, 42, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 34, 7, 15, 8, 35, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 36, 33, 18, 34, 3, 35, 3, 36, 19, 0, 1, 0, 27, 43, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 37, 7, 15, 8, 38, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 39, 33, 18, 34, 3, 35, 3, 36, 19, 0, 1, 0, 27, 44, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 40, 7, 15, 8, 41, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 42, 33, 18, 34, 3, 35, 3, 36, 19, 0, 1, 0, 27, 45, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 43, 7, 15, 8, 44, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 45, 33, 18, 34, 3, 35, 3, 36, 19, 0, 1, 0, 27, 46, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 46, 7, 15, 8, 47, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 48, 33, 18, 34, 3, 35, 3, 36, 19, 0, 0, 0, 23, 47, -1, 20, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 24, 49, 25, 12, 7, 50, 8, 51, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 3, 17, 8, 18, 8, 19, 2, 0, 13, 0, 27, 48, -1, 27, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 7, 52, 8, 16, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 53, 33, 18, 34, 3, 35, 3, 36, 19, 0, 13, 0, 27, 49, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 20, 7, 52, 8, 11, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 54, 33, 18, 34, 3, 35, 3, 36, 19, 0, 13, 0, 27, 50, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 22, 7, 52, 8, 23, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 55, 33, 18, 34, 3, 35, 3, 36, 19, 0, 13, 0, 27, 51, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 25, 7, 52, 8, 26, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 56, 33, 18, 34, 3, 35, 3, 36, 19, 0, 0, 0, 23, 52, -1, 20, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 24, 40, 25, 12, 7, 57, 8, 58, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 3, 17, 8, 18, 8, 19, 2, 0, 18, 0, 27, 53, -1, 27, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 7, 59, 8, 16, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 60, 33, 18, 34, 3, 35, 3, 36, 19, 0, 18, 0, 27, 54, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 20, 7, 59, 8, 11, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 61, 33, 18, 34, 3, 35, 3, 36, 19, 0, 18, 0, 27, 55, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 22, 7, 59, 8, 23, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 62, 33, 18, 34, 3, 35, 3, 36, 19, 0, 18, 0, 27, 56, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 25, 7, 59, 8, 26, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 63, 33, 18, 34, 3, 35, 3, 36, 19, 0, 18, 0, 27, 57, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 28, 7, 59, 8, 29, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 64, 33, 18, 34, 3, 35, 3, 36, 19, 0, 18, 0, 27, 58, -1, 28, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 31, 7, 59, 8, 32, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 28, 3, 29, 3, 30, 1, 31, 3, 32, 65, 33, 18, 34, 3, 35, 3, 36, 19, 0, 0, 0, 23, 54, -1, 20, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 24, 66, 25, 40, 7, 67, 8, 68, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 3, 17, 8, 18, 8, 19, 2, 0, 25, 0, 60, 59, -1, 30, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 7, 69, 8, 70, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 1, 16, 1, 17, 8, 19, 2, 61, 6, 62, 2, 63, 2, 64, 2, 65, 6, 66, 3, 67, 3, 32, 71, 36, 72, 68, 72, 69, 3, 70, 3, 71, 73, 0, 25, 0, 73, 72, -1, 19, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 74, 7, 69, 8, 75, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 3, 17, 8, 18, 8, 19, 2, 0, 25, 0, 60, 74, -1, 31, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 76, 7, 69, 8, 77, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 1, 16, 1, 17, 8, 19, 2, 61, 6, 62, 2, 63, 2, 64, 2, 65, 6, 66, 3, 67, 3, 32, 78, 36, 72, 68, 72, 69, 3, 70, 3, 71, 73, 0, 25, 0, 73, 75, -1, 19, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 25, 79, 7, 69, 8, 80, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 3, 17, 8, 18, 8, 19, 2, 0, 0, 0, 77, 76, -1, 5, 2, 0, 78, 19, 79, 1, 80, 1, 81, 2, 0, 30, 0, 83, 82, -1, 20, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 24, 81, 25, 81, 7, 82, 8, 83, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 18, 8, 19, 2, 0, 31, 0, 85, 84, -1, 19, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 86, 84, 9, 6, 10, 7, 87, 85, 88, 1, 89, 84, 90, 3, 91, 3, 92, 19, 93, 19, 94, 72, 95, 86, 96, 3, 97, 87, 0, 0, 0, 99, 98, -1, 28, 2, 0, 3, 3, 4, 2, 5, 2, 6, 3, 24, 88, 25, 89, 7, 67, 8, 40, 9, 6, 10, 7, 11, 0, 12, 0, 13, 0, 14, 0, 15, 3, 16, 1, 17, 8, 19, 2, 61, 6, 62, 90, 63, 2, 64, 6, 65, 2, 66, 3, 67, 3, 100, 72, 101, 3, 0 "conns" - 30, 0, 102, 101, 2, 0, 33, 0, 104, 103, 2, 0 + 30, 0, 103, 102, 2, 0, 33, 0, 105, 104, 2, 0 diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp index cdd9176a1b3..48a2fd564b8 100644 --- a/scene/animation/tween.cpp +++ b/scene/animation/tween.cpp @@ -132,9 +132,10 @@ void Tween::_bind_methods() { ObjectTypeDB::bind_method(_MD("remove","object","key"),&Tween::remove ); ObjectTypeDB::bind_method(_MD("remove_all"),&Tween::remove_all ); ObjectTypeDB::bind_method(_MD("seek"),&Tween::seek ); + ObjectTypeDB::bind_method(_MD("get_runtime"),&Tween::get_runtime ); - ObjectTypeDB::bind_method(_MD("interpolate_property","object","property","initial_val","final_val","times_in_sec","trans_type","ease_type"),&Tween::interpolate_property ); - ObjectTypeDB::bind_method(_MD("interpolate_method","object","method","initial_val","final_val","times_in_sec","trans_type","ease_type"),&Tween::interpolate_method ); + ObjectTypeDB::bind_method(_MD("interpolate_property","object","property","initial_val","final_val","times_in_sec","trans_type","ease_type","delay"),&Tween::interpolate_property, DEFVAL(0) ); + ObjectTypeDB::bind_method(_MD("interpolate_method","object","method","initial_val","final_val","times_in_sec","trans_type","ease_type","delay"),&Tween::interpolate_method, DEFVAL(0) ); ADD_SIGNAL( MethodInfo("tween_start", PropertyInfo( Variant::OBJECT,"object"), PropertyInfo( Variant::STRING,"key")) ); ADD_SIGNAL( MethodInfo("tween_step", PropertyInfo( Variant::OBJECT,"object"), PropertyInfo( Variant::STRING,"key"), PropertyInfo( Variant::REAL,"elapsed"), PropertyInfo( Variant::OBJECT,"value")) ); @@ -168,16 +169,16 @@ Variant Tween::_run_equation(InterpolateData& p_data) { Variant result; #define APPLY_EQUATION(element)\ - r.element = _run_equation(p_data.trans_type, p_data.ease_type, p_data.elapsed, i.element, d.element, p_data.times_in_sec); + r.element = _run_equation(p_data.trans_type, p_data.ease_type, p_data.elapsed - p_data.delay, i.element, d.element, p_data.times_in_sec); switch(initial_val.get_type()) { case Variant::INT: - result = (int) _run_equation(p_data.trans_type, p_data.ease_type, p_data.elapsed, (int) initial_val, (int) delta_val, p_data.times_in_sec); + result = (int) _run_equation(p_data.trans_type, p_data.ease_type, p_data.elapsed - p_data.delay, (int) initial_val, (int) delta_val, p_data.times_in_sec); break; case Variant::REAL: - result = _run_equation(p_data.trans_type, p_data.ease_type, p_data.elapsed, (real_t) initial_val, (real_t) delta_val, p_data.times_in_sec); + result = _run_equation(p_data.trans_type, p_data.ease_type, p_data.elapsed - p_data.delay, (real_t) initial_val, (real_t) delta_val, p_data.times_in_sec); break; case Variant::VECTOR2: @@ -350,26 +351,33 @@ void Tween::_tween_process(float p_delta) { InterpolateData& data = E->get(); if(!data.active) continue; - if(data.elapsed == data.times_in_sec) { + if(data.finish) { if(!repeat) continue; data.elapsed = 0; + data.finish = false; } - if(data.elapsed == 0) + bool prev_delaying = data.elapsed <= data.delay; + data.elapsed += p_delta; + if(data.elapsed < data.delay) + continue; + else if(prev_delaying) emit_signal("tween_start",data.object,data.key); - data.elapsed += p_delta; - if(data.elapsed > data.times_in_sec) - data.elapsed = data.times_in_sec; + if(data.elapsed > (data.delay + data.times_in_sec)) { + + data.elapsed = data.delay + data.times_in_sec; + data.finish = true; + } Variant result = _run_equation(data); emit_signal("tween_step",data.object,data.key,data.elapsed,result); _apply_tween_value(data, result); - if(data.elapsed == data.times_in_sec) + if(data.finish) emit_signal("tween_complete",data.object,data.key); } } @@ -452,8 +460,12 @@ bool Tween::reset(Variant p_object, String p_key) { for(List::Element *E=interpolates.front();E;E=E->next()) { InterpolateData& data = E->get(); - if(data.object == p_object && data.key == p_key) + if(data.object == p_object && data.key == p_key) { + + data.elapsed = 0; + data.finish = false; _apply_tween_value(data, data.initial_val); + } } return true; } @@ -463,6 +475,8 @@ bool Tween::reset_all() { for(List::Element *E=interpolates.front();E;E=E->next()) { InterpolateData& data = E->get(); + data.elapsed = 0; + data.finish = false; _apply_tween_value(data, data.initial_val); } return true; @@ -548,8 +562,10 @@ bool Tween::seek(real_t p_time) { InterpolateData& data = E->get(); data.elapsed = p_time; - if(data.elapsed > data.times_in_sec) - data.elapsed = data.times_in_sec; + if(data.elapsed < data.delay) + continue; + else if(data.elapsed > (data.delay + data.times_in_sec)) + data.elapsed = (data.delay + data.times_in_sec); Variant result = _run_equation(data); @@ -558,6 +574,19 @@ bool Tween::seek(real_t p_time) { return true; } +real_t Tween::get_runtime() { + + real_t runtime = 0; + for(List::Element *E=interpolates.front();E;E=E->next()) { + + InterpolateData& data = E->get(); + real_t t = data.delay + data.times_in_sec; + if(t > runtime) + runtime = t; + } + return runtime; +} + bool Tween::_calc_delta_val(InterpolateData& p_data) { Variant& initial_val = p_data.initial_val; @@ -666,11 +695,18 @@ bool Tween::interpolate_property(Variant p_object , real_t p_times_in_sec , TransitionType p_trans_type , EaseType p_ease_type + , real_t p_delay ) { + // convert INT to REAL is better for interpolaters + if(p_initial_val.get_type() == Variant::INT) p_initial_val = p_initial_val.operator real_t(); + if(p_final_val.get_type() == Variant::INT) p_final_val = p_final_val.operator real_t(); ERR_FAIL_COND_V(p_object.get_type() != Variant::OBJECT, false); ERR_FAIL_COND_V(p_initial_val.get_type() != p_final_val.get_type(), false); ERR_FAIL_COND_V(p_times_in_sec <= 0, false); + ERR_FAIL_COND_V(p_trans_type < 0 || p_trans_type >= TRANS_COUNT, false); + ERR_FAIL_COND_V(p_ease_type < 0 || p_ease_type >= EASE_COUNT, false); + ERR_FAIL_COND_V(p_delay < 0, false); bool prop_found = false; Object *obj = (Object *) p_object; @@ -690,6 +726,7 @@ bool Tween::interpolate_property(Variant p_object InterpolateData data; data.active = true; data.is_method = false; + data.finish = false; data.elapsed = 0; data.object = p_object; @@ -699,6 +736,7 @@ bool Tween::interpolate_property(Variant p_object data.times_in_sec = p_times_in_sec; data.trans_type = p_trans_type; data.ease_type = p_ease_type; + data.delay = p_delay; if(!_calc_delta_val(data)) return false; @@ -714,11 +752,18 @@ bool Tween::interpolate_method(Variant p_object , real_t p_times_in_sec , TransitionType p_trans_type , EaseType p_ease_type + , real_t p_delay ) { + // convert INT to REAL is better for interpolaters + if(p_initial_val.get_type() == Variant::INT) p_initial_val = p_initial_val.operator real_t(); + if(p_final_val.get_type() == Variant::INT) p_final_val = p_final_val.operator real_t(); ERR_FAIL_COND_V(p_object.get_type() != Variant::OBJECT, false); ERR_FAIL_COND_V(p_initial_val.get_type() != p_final_val.get_type(), false); ERR_FAIL_COND_V(p_times_in_sec <= 0, false); + ERR_FAIL_COND_V(p_trans_type < 0 || p_trans_type >= TRANS_COUNT, false); + ERR_FAIL_COND_V(p_ease_type < 0 || p_ease_type >= EASE_COUNT, false); + ERR_FAIL_COND_V(p_delay < 0, false); Object *obj = (Object *) p_object; ERR_FAIL_COND_V(!obj->has_method(p_method), false); @@ -726,6 +771,7 @@ bool Tween::interpolate_method(Variant p_object InterpolateData data; data.active = true; data.is_method = true; + data.finish = false; data.elapsed = 0; data.object = p_object; @@ -735,6 +781,7 @@ bool Tween::interpolate_method(Variant p_object data.times_in_sec = p_times_in_sec; data.trans_type = p_trans_type; data.ease_type = p_ease_type; + data.delay = p_delay; if(!_calc_delta_val(data)) return false; diff --git a/scene/animation/tween.h b/scene/animation/tween.h index 7dd917dc8ee..78df7d9c93c 100644 --- a/scene/animation/tween.h +++ b/scene/animation/tween.h @@ -72,6 +72,7 @@ private: struct InterpolateData { bool active; bool is_method; + bool finish; real_t elapsed; Variant object; @@ -82,6 +83,7 @@ private: real_t times_in_sec; TransitionType trans_type; EaseType ease_type; + real_t delay; }; String autoplay; @@ -138,6 +140,7 @@ public: bool remove_all(); bool seek(real_t p_time); + real_t get_runtime(); bool interpolate_property(Variant p_object , String p_property @@ -146,6 +149,7 @@ public: , real_t p_times_in_sec , TransitionType p_trans_type , EaseType p_ease_type + , real_t p_delay = 0 ); bool interpolate_method(Variant p_object @@ -155,6 +159,7 @@ public: , real_t p_times_in_sec , TransitionType p_trans_type , EaseType p_ease_type + , real_t p_delay = 0 ); Tween();