mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-02-22 13:33:13 +00:00
Changes on how animation plays on frame tags
If the animation starts playing on a frame outside a tag, the animation will not limit itself to the tags later on as it plays. The animation will play only on a tag, if it started on a frame which has that tag. I also made it react to frame and tag changes, if they happen while the animation is running. I also added a play_animation() method in AnimationTimeline.gd, to reduce duplicate code found in _on_PlayForward_toggled() and _on_PlayBackwards_toggled()
This commit is contained in:
parent
81ce4f68b1
commit
ba2b8aae91
2 changed files with 82 additions and 42 deletions
|
@ -3,6 +3,8 @@ extends Panel
|
||||||
var fps := 6.0
|
var fps := 6.0
|
||||||
var animation_loop := 1 # 0 is no loop, 1 is cycle loop, 2 is ping-pong loop
|
var animation_loop := 1 # 0 is no loop, 1 is cycle loop, 2 is ping-pong loop
|
||||||
var animation_forward := true
|
var animation_forward := true
|
||||||
|
var first_frame := 0
|
||||||
|
var last_frame := Global.canvases.size() - 1
|
||||||
|
|
||||||
onready var timeline_scroll : ScrollContainer = $AnimationContainer/TimelineContainer/TimelineScroll
|
onready var timeline_scroll : ScrollContainer = $AnimationContainer/TimelineContainer/TimelineScroll
|
||||||
onready var tag_scroll_container : ScrollContainer = $AnimationContainer/TimelineContainer/OpacityAndTagContainer/TagScroll
|
onready var tag_scroll_container : ScrollContainer = $AnimationContainer/TimelineContainer/OpacityAndTagContainer/TagScroll
|
||||||
|
@ -175,54 +177,23 @@ func _on_LoopAnim_pressed() -> void:
|
||||||
Global.loop_animation_button.texture_hover = load("res://Assets/Graphics/%s Themes/Timeline/Loop_None_Hover.png" % Global.theme_type)
|
Global.loop_animation_button.texture_hover = load("res://Assets/Graphics/%s Themes/Timeline/Loop_None_Hover.png" % Global.theme_type)
|
||||||
Global.loop_animation_button.hint_tooltip = "No loop"
|
Global.loop_animation_button.hint_tooltip = "No loop"
|
||||||
|
|
||||||
func _on_PlayForward_toggled(button_pressed : bool) -> void:
|
|
||||||
Global.play_backwards.pressed = false
|
|
||||||
if Global.canvases.size() == 1:
|
|
||||||
Global.play_forward.pressed = false
|
|
||||||
return
|
|
||||||
|
|
||||||
if button_pressed:
|
func _on_PlayForward_toggled(button_pressed : bool) -> void:
|
||||||
Global.animation_timer.wait_time = 1 / fps
|
play_animation(button_pressed, true)
|
||||||
Global.animation_timer.start()
|
|
||||||
animation_forward = true
|
|
||||||
else:
|
|
||||||
Global.animation_timer.stop()
|
|
||||||
|
|
||||||
func _on_PlayBackwards_toggled(button_pressed : bool) -> void:
|
func _on_PlayBackwards_toggled(button_pressed : bool) -> void:
|
||||||
Global.play_forward.pressed = false
|
play_animation(button_pressed, false)
|
||||||
if Global.canvases.size() == 1:
|
|
||||||
Global.play_backwards.pressed = false
|
|
||||||
return
|
|
||||||
|
|
||||||
if button_pressed:
|
|
||||||
Global.animation_timer.wait_time = 1 / fps
|
|
||||||
Global.animation_timer.start()
|
|
||||||
animation_forward = false
|
|
||||||
else:
|
|
||||||
Global.animation_timer.stop()
|
|
||||||
|
|
||||||
func _on_NextFrame_pressed() -> void:
|
|
||||||
if Global.current_frame < Global.canvases.size() - 1:
|
|
||||||
Global.current_frame += 1
|
|
||||||
|
|
||||||
func _on_PreviousFrame_pressed() -> void:
|
|
||||||
if Global.current_frame > 0:
|
|
||||||
Global.current_frame -= 1
|
|
||||||
|
|
||||||
func _on_LastFrame_pressed() -> void:
|
|
||||||
Global.current_frame = Global.canvases.size() - 1
|
|
||||||
|
|
||||||
func _on_FirstFrame_pressed() -> void:
|
|
||||||
Global.current_frame = 0
|
|
||||||
|
|
||||||
func _on_AnimationTimer_timeout() -> void:
|
func _on_AnimationTimer_timeout() -> void:
|
||||||
var first_frame := 0
|
# var first_frame := 0
|
||||||
var last_frame := Global.canvases.size() - 1
|
# var last_frame := Global.canvases.size() - 1
|
||||||
if Global.play_only_tags:
|
# if Global.play_only_tags:
|
||||||
for tag in Global.animation_tags:
|
# for tag in Global.animation_tags:
|
||||||
if Global.current_frame + 1 >= tag[2] && Global.current_frame + 1 <= tag[3]:
|
# if Global.current_frame + 1 >= tag[2] && Global.current_frame + 1 <= tag[3]:
|
||||||
first_frame = tag[2] - 1
|
# first_frame = tag[2] - 1
|
||||||
last_frame = min(Global.canvases.size() - 1, tag[3] - 1)
|
# last_frame = min(Global.canvases.size() - 1, tag[3] - 1)
|
||||||
|
|
||||||
if animation_forward:
|
if animation_forward:
|
||||||
if Global.current_frame < last_frame:
|
if Global.current_frame < last_frame:
|
||||||
|
@ -254,6 +225,53 @@ func _on_AnimationTimer_timeout() -> void:
|
||||||
animation_forward = true
|
animation_forward = true
|
||||||
_on_AnimationTimer_timeout()
|
_on_AnimationTimer_timeout()
|
||||||
|
|
||||||
|
|
||||||
|
func play_animation(play : bool, forward_dir : bool) -> void:
|
||||||
|
if forward_dir:
|
||||||
|
Global.play_backwards.pressed = false
|
||||||
|
else:
|
||||||
|
Global.play_forward.pressed = false
|
||||||
|
if Global.canvases.size() == 1:
|
||||||
|
if forward_dir:
|
||||||
|
Global.play_forward.pressed = false
|
||||||
|
else:
|
||||||
|
Global.play_backwards.pressed = false
|
||||||
|
return
|
||||||
|
|
||||||
|
first_frame = 0
|
||||||
|
last_frame = Global.canvases.size() - 1
|
||||||
|
if Global.play_only_tags:
|
||||||
|
for tag in Global.animation_tags:
|
||||||
|
if Global.current_frame + 1 >= tag[2] && Global.current_frame + 1 <= tag[3]:
|
||||||
|
first_frame = tag[2] - 1
|
||||||
|
last_frame = min(Global.canvases.size() - 1, tag[3] - 1)
|
||||||
|
|
||||||
|
if play:
|
||||||
|
Global.animation_timer.wait_time = 1 / fps
|
||||||
|
Global.animation_timer.start()
|
||||||
|
animation_forward = forward_dir
|
||||||
|
else:
|
||||||
|
Global.animation_timer.stop()
|
||||||
|
|
||||||
|
|
||||||
|
func _on_NextFrame_pressed() -> void:
|
||||||
|
if Global.current_frame < Global.canvases.size() - 1:
|
||||||
|
Global.current_frame += 1
|
||||||
|
|
||||||
|
|
||||||
|
func _on_PreviousFrame_pressed() -> void:
|
||||||
|
if Global.current_frame > 0:
|
||||||
|
Global.current_frame -= 1
|
||||||
|
|
||||||
|
|
||||||
|
func _on_LastFrame_pressed() -> void:
|
||||||
|
Global.current_frame = Global.canvases.size() - 1
|
||||||
|
|
||||||
|
|
||||||
|
func _on_FirstFrame_pressed() -> void:
|
||||||
|
Global.current_frame = 0
|
||||||
|
|
||||||
|
|
||||||
func _on_FPSValue_value_changed(value) -> void:
|
func _on_FPSValue_value_changed(value) -> void:
|
||||||
fps = float(value)
|
fps = float(value)
|
||||||
Global.animation_timer.wait_time = 1 / fps
|
Global.animation_timer.wait_time = 1 / fps
|
||||||
|
|
|
@ -539,6 +539,17 @@ func canvases_changed(value : Array) -> void:
|
||||||
|
|
||||||
layers[i][3].add_child(frame_button)
|
layers[i][3].add_child(frame_button)
|
||||||
|
|
||||||
|
# This is useful in case tagged frames get deleted DURING the animation is playing
|
||||||
|
# otherwise, this code is useless in this context, since these values are being set
|
||||||
|
# when the play buttons get pressed, anyway
|
||||||
|
animation_timeline.first_frame = 0
|
||||||
|
animation_timeline.last_frame = canvases.size() - 1
|
||||||
|
if play_only_tags:
|
||||||
|
for tag in animation_tags:
|
||||||
|
if current_frame + 1 >= tag[2] && current_frame + 1 <= tag[3]:
|
||||||
|
animation_timeline.first_frame = tag[2] - 1
|
||||||
|
animation_timeline.last_frame = min(canvases.size() - 1, tag[3] - 1)
|
||||||
|
|
||||||
func clear_canvases() -> void:
|
func clear_canvases() -> void:
|
||||||
for child in canvas_parent.get_children():
|
for child in canvas_parent.get_children():
|
||||||
if child is Canvas:
|
if child is Canvas:
|
||||||
|
@ -694,6 +705,17 @@ func animation_tags_changed(value : Array) -> void:
|
||||||
tag_c.get_node("Line2D").points[2] = Vector2(tag_c.rect_min_size.x, 0)
|
tag_c.get_node("Line2D").points[2] = Vector2(tag_c.rect_min_size.x, 0)
|
||||||
tag_c.get_node("Line2D").points[3] = Vector2(tag_c.rect_min_size.x, 32)
|
tag_c.get_node("Line2D").points[3] = Vector2(tag_c.rect_min_size.x, 32)
|
||||||
|
|
||||||
|
# This is useful in case tags get modified DURING the animation is playing
|
||||||
|
# otherwise, this code is useless in this context, since these values are being set
|
||||||
|
# when the play buttons get pressed, anyway
|
||||||
|
animation_timeline.first_frame = 0
|
||||||
|
animation_timeline.last_frame = canvases.size() - 1
|
||||||
|
if play_only_tags:
|
||||||
|
for tag in animation_tags:
|
||||||
|
if current_frame + 1 >= tag[2] && current_frame + 1 <= tag[3]:
|
||||||
|
animation_timeline.first_frame = tag[2] - 1
|
||||||
|
animation_timeline.last_frame = min(canvases.size() - 1, tag[3] - 1)
|
||||||
|
|
||||||
|
|
||||||
func update_hint_tooltips() -> void:
|
func update_hint_tooltips() -> void:
|
||||||
var root = get_tree().get_root()
|
var root = get_tree().get_root()
|
||||||
|
|
Loading…
Add table
Reference in a new issue