diff options
author | sanikoyes <sanikoyes@163.com> | 2014-08-20 16:39:28 +0800 |
---|---|---|
committer | sanikoyes <sanikoyes@163.com> | 2014-08-20 16:39:28 +0800 |
commit | 87faf1c046ddc024cf956096f8ad342b97f3c2d4 (patch) | |
tree | 4fafba9c85b8a4d4f6ea57d98d09d4f0a0feffb6 | |
parent | b51da466e9fc25fb39e499f1d521a2a0b78c63cf (diff) |
Add tween seek/repeat support
Add tween demo
-rw-r--r-- | demos/misc/tween/engine.cfg | 10 | ||||
-rw-r--r-- | demos/misc/tween/main.gd | 127 | ||||
-rw-r--r-- | demos/misc/tween/main.xml | 332 | ||||
-rw-r--r-- | scene/animation/tween.cpp | 54 | ||||
-rw-r--r-- | scene/animation/tween.h | 6 |
5 files changed, 525 insertions, 4 deletions
diff --git a/demos/misc/tween/engine.cfg b/demos/misc/tween/engine.cfg new file mode 100644 index 0000000000..7966a56830 --- /dev/null +++ b/demos/misc/tween/engine.cfg @@ -0,0 +1,10 @@ +[application] + +name="Tween Demo" +main_scene="res://main.xml" +icon="icon.png" + +[display] + +stretch_mode="2d" +stretch_aspect="keep_width" diff --git a/demos/misc/tween/main.gd b/demos/misc/tween/main.gd new file mode 100644 index 0000000000..5f6828f6f4 --- /dev/null +++ b/demos/misc/tween/main.gd @@ -0,0 +1,127 @@ + +extends Control + +# member variables here, example: +# var a=2 +# var b="textvar" + +var trans = ["linear", "sine", "quint", "quart", "quad", "expo", "elastic", "cubic", "circ", "bounce", "back"] +var eases = ["in", "out", "in_out", "out_in"] +var modes = ["move", "color", "scale", "rotate", "repeat", "pause"] + +var state = { + trans = Tween.TRANS_LINEAR, + eases = Tween.EASE_IN, +} + +func _ready(): + for index in range(trans.size()): + var name = trans[index] + get_node("trans/" + name).connect("pressed", self, "on_trans_changed", [name, index]) + + for index in range(eases.size()): + var name = eases[index] + get_node("eases/" + name).connect("pressed", self, "on_eases_changed", [name, index]) + + for index in range(modes.size()): + var name = modes[index] + get_node("modes/" + name).connect("pressed", self, "on_modes_changed", [name]) + + get_node("color/color_from").set_color(Color(1, 0, 0, 1)) + get_node("color/color_from").connect("color_changed", self, "on_color_changed") + + get_node("color/color_to").set_color(Color(0, 1, 1, 1)) + get_node("color/color_to").connect("color_changed", self, "on_color_changed") + + get_node("trans/linear").set_pressed(true) + get_node("eases/in").set_pressed(true) + get_node("modes/move").set_pressed(true) + get_node("modes/repeat").set_pressed(true) + + reset_tween() + + # Initalization here + pass + +func on_trans_changed(name, index): + for index in range(trans.size()): + var pressed = trans[index] == name + var btn = get_node("trans/" + trans[index]) + + btn.set_pressed(pressed) + btn.set_ignore_mouse(pressed) + + state.trans = index + reset_tween() + +func on_eases_changed(name, index): + for index in range(eases.size()): + var pressed = eases[index] == name + var btn = get_node("eases/" + eases[index]) + + btn.set_pressed(pressed) + btn.set_ignore_mouse(pressed) + + state.eases = index + reset_tween() + +func on_modes_changed(name): + var tween = get_node("tween") + if name == "pause": + if get_node("modes/pause").is_pressed(): + tween.stop_all() + get_node("timeline").show() + else: + tween.resume_all() + get_node("timeline").hide() + else: + reset_tween() + +func on_color_changed(color): + reset_tween() + +func reset_tween(): + var tween = get_node("tween") + tween.reset_all() + tween.remove_all() + + var sprite = get_node("tween/area/sprite") + + if get_node("modes/move").is_pressed(): + tween.interpolate_method(sprite, "set_pos", Vector2(0,0), Vector2(736, 184), 2, state.trans, state.eases) + + 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) + 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) + + if get_node("modes/rotate").is_pressed(): + tween.interpolate_method(sprite, "set_rot", 0.0, 6.28, 2, state.trans, state.eases) + + tween.set_repeat(get_node("modes/repeat").is_pressed()) + tween.start() + + if get_node("modes/pause").is_pressed(): + tween.stop_all() + get_node("timeline").show() + get_node("timeline").set_value(0) + else: + tween.resume_all() + get_node("timeline").hide() + +func _on_tween_step( object, key, elapsed, value ): + var timeline = get_node("timeline") + var ratio = 100 * (elapsed / 2) + timeline.set_value(ratio) + + +func _on_timeline_value_changed( value ): + if !get_node("modes/pause").is_pressed(): + return + + var tween = get_node("tween") + tween.seek(2.0 * value / 100) + diff --git a/demos/misc/tween/main.xml b/demos/misc/tween/main.xml new file mode 100644 index 0000000000..8c6c9c4639 --- /dev/null +++ b/demos/misc/tween/main.xml @@ -0,0 +1,332 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<resource_file type="PackedScene" subresource_count="3" version="1.0" version_name="Godot Engine v1.0.3917-beta1"> + <ext_resource path="res://icon.png" type="Texture"></ext_resource> + <ext_resource path="res://main.gd" type="Script"></ext_resource> + <main_resource> + <dictionary name="_bundled" shared="false"> + <string> "names" </string> + <string_array len="105"> + <string> "main" </string> + <string> "Control" </string> + <string> "_import_path" </string> + <string> "visibility/visible" </string> + <string> "visibility/opacity" </string> + <string> "visibility/self_opacity" </string> + <string> "visibility/behind_parent" </string> + <string> "margin/right" </string> + <string> "margin/bottom" </string> + <string> "transform/rot" </string> + <string> "transform/scale" </string> + <string> "focus_neighbour/left" </string> + <string> "focus_neighbour/top" </string> + <string> "focus_neighbour/right" </string> + <string> "focus_neighbour/bottom" </string> + <string> "focus/ignore_mouse" </string> + <string> "focus/stop_mouse" </string> + <string> "size_flags/horizontal" </string> + <string> "size_flags/vertical" </string> + <string> "size_flags/stretch_ratio" </string> + <string> "script/script" </string> + <string> "__meta__" </string> + <string> "trans" </string> + <string> "VBoxContainer" </string> + <string> "margin/left" </string> + <string> "margin/top" </string> + <string> "linear" </string> + <string> "Button" </string> + <string> "disabled" </string> + <string> "pressed" </string> + <string> "toggle_mode" </string> + <string> "click_on_press" </string> + <string> "text" </string> + <string> "icon" </string> + <string> "flat" </string> + <string> "clip_text" </string> + <string> "align" </string> + <string> "sine" </string> + <string> "quint" </string> + <string> "quart" </string> + <string> "quad" </string> + <string> "expo" </string> + <string> "elastic" </string> + <string> "cubic" </string> + <string> "circ" </string> + <string> "bounce" </string> + <string> "back" </string> + <string> "eases" </string> + <string> "in" </string> + <string> "out" </string> + <string> "in_out" </string> + <string> "out_in" </string> + <string> "modes" </string> + <string> "move" </string> + <string> "color" </string> + <string> "scale" </string> + <string> "rotate" </string> + <string> "repeat" </string> + <string> "pause" </string> + <string> "label_1" </string> + <string> "Label" </string> + <string> "range/min" </string> + <string> "range/max" </string> + <string> "range/step" </string> + <string> "range/page" </string> + <string> "range/value" </string> + <string> "range/exp_edit" </string> + <string> "rounded_values" </string> + <string> "valign" </string> + <string> "autowrap" </string> + <string> "uppercase" </string> + <string> "percent_visible" </string> + <string> "color_from" </string> + <string> "ColorPicker" </string> + <string> "label_2" </string> + <string> "color_to" </string> + <string> "tween" </string> + <string> "Tween" </string> + <string> "playback/active" </string> + <string> "playback/repeat" </string> + <string> "playback/speed" </string> + <string> "area" </string> + <string> "Panel" </string> + <string> "sprite" </string> + <string> "Sprite" </string> + <string> "transform/pos" </string> + <string> "texture" </string> + <string> "centered" </string> + <string> "offset" </string> + <string> "flip_h" </string> + <string> "flip_v" </string> + <string> "vframes" </string> + <string> "hframes" </string> + <string> "frame" </string> + <string> "modulate" </string> + <string> "region" </string> + <string> "region_rect" </string> + <string> "timeline" </string> + <string> "HSlider" </string> + <string> "tick_count" </string> + <string> "ticks_on_borders" </string> + <string> "_on_tween_step" </string> + <string> "tween_step" </string> + <string> "_on_timeline_value_changed" </string> + <string> "value_changed" </string> + </string_array> + <string> "version" </string> + <int> 1 </int> + <string> "conn_count" </string> + <int> 2 </int> + <string> "node_count" </string> + <int> 34 </int> + <string> "variants" </string> + <array len="91" shared="false"> + <node_path> "" </node_path> + <bool> True </bool> + <real> 1 </real> + <bool> False </bool> + <real> 800 </real> + <real> 600 </real> + <real> 0 </real> + <vector2> 1, 1 </vector2> + <int> 2 </int> + <resource resource_type="Script" path="res://main.gd"> </resource> + <dictionary shared="false"> + <string> "__editor_plugin_states__" </string> + <dictionary shared="false"> + <string> "Script" </string> + <dictionary shared="false"> + <string> "current" </string> + <int> 0 </int> + <string> "sources" </string> + <array len="1" shared="false"> + <string> "res://main.gd" </string> + </array> + </dictionary> + <string> "2D" </string> + <dictionary shared="false"> + <string> "pixel_snap" </string> + <bool> False </bool> + <string> "zoom" </string> + <real> 1.360374 </real> + <string> "use_snap" </string> + <bool> True </bool> + <string> "ofs" </string> + <vector2> -220.639, 36.0825 </vector2> + <string> "snap" </string> + <int> 8 </int> + </dictionary> + <string> "3D" </string> + <dictionary shared="false"> + <string> "zfar" </string> + <real> 500 </real> + <string> "fov" </string> + <real> 45 </real> + <string> "viewports" </string> + <array len="4" shared="false"> + <dictionary shared="false"> + <string> "distance" </string> + <real> 4 </real> + <string> "x_rot" </string> + <real> 0 </real> + <string> "y_rot" </string> + <real> 0 </real> + <string> "use_orthogonal" </string> + <bool> False </bool> + <string> "use_environment" </string> + <bool> False </bool> + <string> "pos" </string> + <vector3> 0, 0, 0 </vector3> + </dictionary> + <dictionary shared="false"> + <string> "distance" </string> + <real> 4 </real> + <string> "x_rot" </string> + <real> 0 </real> + <string> "y_rot" </string> + <real> 0 </real> + <string> "use_orthogonal" </string> + <bool> False </bool> + <string> "use_environment" </string> + <bool> False </bool> + <string> "pos" </string> + <vector3> 0, 0, 0 </vector3> + </dictionary> + <dictionary shared="false"> + <string> "distance" </string> + <real> 4 </real> + <string> "x_rot" </string> + <real> 0 </real> + <string> "y_rot" </string> + <real> 0 </real> + <string> "use_orthogonal" </string> + <bool> False </bool> + <string> "use_environment" </string> + <bool> False </bool> + <string> "pos" </string> + <vector3> 0, 0, 0 </vector3> + </dictionary> + <dictionary shared="false"> + <string> "distance" </string> + <real> 4 </real> + <string> "x_rot" </string> + <real> 0 </real> + <string> "y_rot" </string> + <real> 0 </real> + <string> "use_orthogonal" </string> + <bool> False </bool> + <string> "use_environment" </string> + <bool> False </bool> + <string> "pos" </string> + <vector3> 0, 0, 0 </vector3> + </dictionary> + </array> + <string> "viewport_mode" </string> + <int> 1 </int> + <string> "default_light" </string> + <bool> True </bool> + <string> "show_grid" </string> + <bool> True </bool> + <string> "show_origin" </string> + <bool> True </bool> + <string> "znear" </string> + <real> 0.1 </real> + </dictionary> + </dictionary> + <string> "__editor_run_settings__" </string> + <dictionary shared="false"> + <string> "custom_args" </string> + <string> "-l $scene" </string> + <string> "run_mode" </string> + <int> 0 </int> + </dictionary> + <string> "__editor_plugin_screen__" </string> + <string> "Script" </string> + </dictionary> + <real> 56 </real> + <real> 256 </real> + <real> 129 </real> + <real> 582 </real> + <real> 73 </real> + <real> 26 </real> + <string> "linear" </string> + <resource name=""></resource> <int> 1 </int> + <real> 30 </real> + <string> "sine" </string> + <real> 60 </real> + <real> 86 </real> + <string> "quint" </string> + <real> 90 </real> + <real> 116 </real> + <string> "quart" </string> + <real> 120 </real> + <real> 146 </real> + <string> "quad" </string> + <real> 150 </real> + <real> 176 </real> + <string> "expo" </string> + <real> 180 </real> + <real> 206 </real> + <string> "elastic" </string> + <real> 210 </real> + <real> 236 </real> + <string> "cubic" </string> + <real> 240 </real> + <real> 266 </real> + <string> "circ" </string> + <real> 270 </real> + <real> 296 </real> + <string> "bounce" </string> + <real> 300 </real> + <real> 326 </real> + <string> "back" </string> + <real> 152 </real> + <real> 215 </real> + <real> 372 </real> + <real> 63 </real> + <string> "in" </string> + <string> "out" </string> + <string> "in_out" </string> + <string> "out_in" </string> + <real> 305 </real> + <real> 402 </real> + <real> 65 </real> + <string> "move" </string> + <string> "color" </string> + <string> "scale" </string> + <string> "rotate" </string> + <string> "repeat" </string> + <string> "pause" </string> + <real> 384 </real> + <real> 760 </real> + <real> 592 </real> + <real> 376 </real> + <real> 19 </real> + <string> "Color From:" </string> + <int> 0 </int> + <real> -1 </real> + <real> 23 </real> + <real> 174 </real> + <real> 178 </real> + <real> 197 </real> + <string> "Color To:" </string> + <real> 201 </real> + <real> 352 </real> + <real> 32 </real> + <real> 768 </real> + <real> 216 </real> + <vector2> 0, 0 </vector2> + <resource resource_type="Texture" path="res://icon.png"> </resource> + <color> 1, 1, 1, 1 </color> + <rect2> 0, 0, 0, 0 </rect2> + <real> 40 </real> + <real> 224 </real> + <real> 100 </real> + </array> + <string> "nodes" </string> + <int_array len="1948"> -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 </int_array> + <string> "conns" </string> + <int_array len="12"> 30, 0, 102, 101, 2, 0, 33, 0, 104, 103, 2, 0 </int_array> + </dictionary> + + </main_resource> +</resource_file> diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp index eebb0d6777..305e105fdd 100644 --- a/scene/animation/tween.cpp +++ b/scene/animation/tween.cpp @@ -37,6 +37,10 @@ bool Tween::_set(const StringName& p_name, const Variant& p_value) { } else if (name=="playback/active") { set_active(p_value); + + } else if (name=="playback/repeat") { + set_repeat(p_value); + } return true; } @@ -51,13 +55,18 @@ bool Tween::_get(const StringName& p_name,Variant &r_ret) const { } else if (name=="playback/active") { r_ret=is_active(); + } else if(name=="playback/repeat") { + + r_ret=is_repeat(); } + return true; } void Tween::_get_property_list(List<PropertyInfo> *p_list) const { p_list->push_back( PropertyInfo( Variant::BOOL, "playback/active", PROPERTY_HINT_NONE,"" ) ); + p_list->push_back( PropertyInfo( Variant::BOOL, "playback/repeat", PROPERTY_HINT_NONE,"" ) ); p_list->push_back( PropertyInfo( Variant::REAL, "playback/speed", PROPERTY_HINT_RANGE, "-64,64,0.01") ); } @@ -104,6 +113,9 @@ void Tween::_bind_methods() { ObjectTypeDB::bind_method(_MD("is_active"),&Tween::is_active ); ObjectTypeDB::bind_method(_MD("set_active","active"),&Tween::set_active ); + ObjectTypeDB::bind_method(_MD("is_repeat"),&Tween::is_repeat ); + ObjectTypeDB::bind_method(_MD("set_repeat","repeat"),&Tween::set_repeat ); + ObjectTypeDB::bind_method(_MD("set_speed","speed"),&Tween::set_speed); ObjectTypeDB::bind_method(_MD("get_speed"),&Tween::get_speed); @@ -119,13 +131,14 @@ void Tween::_bind_methods() { ObjectTypeDB::bind_method(_MD("resume_all"),&Tween::resume_all ); ObjectTypeDB::bind_method(_MD("remove"),&Tween::remove ); ObjectTypeDB::bind_method(_MD("remove_all"),&Tween::remove_all ); + ObjectTypeDB::bind_method(_MD("seek"),&Tween::seek ); 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 ); 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::OBJECT,"value")) ); - ADD_SIGNAL( MethodInfo("tween_complete", PropertyInfo( Variant::INT,"id")) ); + ADD_SIGNAL( MethodInfo("tween_step", PropertyInfo( Variant::OBJECT,"object"), PropertyInfo( Variant::STRING,"key"), PropertyInfo( Variant::REAL,"elapsed"), PropertyInfo( Variant::OBJECT,"value")) ); + ADD_SIGNAL( MethodInfo("tween_complete", PropertyInfo( Variant::OBJECT,"object"), PropertyInfo( Variant::STRING,"key")) ); //ADD_PROPERTY( PropertyInfo( Variant::BOOL, "activate"), _SCS("set_active"), _SCS("is_active")); @@ -334,8 +347,14 @@ void Tween::_tween_process(float p_delta) { for(List<InterpolateData>::Element *E=interpolates.front();E;E=E->next()) { InterpolateData& data = E->get(); - if(!data.active || data.elapsed == data.times_in_sec) + if(!data.active) continue; + if(data.elapsed == data.times_in_sec) { + + if(!repeat) + continue; + data.elapsed = 0; + } if(data.elapsed == 0) emit_signal("tween_start",data.object,data.key); @@ -345,7 +364,7 @@ void Tween::_tween_process(float p_delta) { data.elapsed = data.times_in_sec; Variant result = _run_equation(data); - emit_signal("tween_step",data.object,data.key,result); + emit_signal("tween_step",data.object,data.key,data.elapsed,result); _apply_tween_value(data, result); @@ -400,6 +419,16 @@ void Tween::set_active(bool p_active) { _set_process(processing,true); } +bool Tween::is_repeat() const { + + return repeat; +} + +void Tween::set_repeat(bool p_repeat) { + + repeat = p_repeat; +} + void Tween::set_speed(float p_speed) { speed_scale=p_speed; @@ -511,6 +540,22 @@ bool Tween::remove_all() { return true; } +bool Tween::seek(real_t p_time) { + + for(List<InterpolateData>::Element *E=interpolates.front();E;E=E->next()) { + + InterpolateData& data = E->get(); + + data.elapsed = p_time; + if(data.elapsed > data.times_in_sec) + data.elapsed = data.times_in_sec; + + Variant result = _run_equation(data); + + _apply_tween_value(data, result); + } + return true; +} bool Tween::_calc_delta_val(InterpolateData& p_data) { @@ -703,6 +748,7 @@ Tween::Tween() { tween_process_mode=TWEEN_PROCESS_IDLE; processing=false; active=false; + repeat=false; speed_scale=1; } diff --git a/scene/animation/tween.h b/scene/animation/tween.h index 5a8186cc21..7dd917dc8e 100644 --- a/scene/animation/tween.h +++ b/scene/animation/tween.h @@ -88,6 +88,7 @@ private: TweenProcessMode tween_process_mode; bool processing; bool active; + bool repeat; float speed_scale; List<InterpolateData> interpolates; @@ -117,6 +118,9 @@ public: bool is_active() const; void set_active(bool p_active); + bool is_repeat() const; + void set_repeat(bool p_repeat); + void set_tween_process_mode(TweenProcessMode p_mode); TweenProcessMode get_tween_process_mode() const; @@ -133,6 +137,8 @@ public: bool remove(Variant p_object, String p_key); bool remove_all(); + bool seek(real_t p_time); + bool interpolate_property(Variant p_object , String p_property , Variant p_initial_val |