2020-06-11 23:27:21 +00:00
|
|
|
extends Node2D
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
var frame: int = 0
|
|
|
|
onready var animation_timer: Timer = $AnimationTimer
|
2020-06-11 23:27:21 +00:00
|
|
|
|
2020-08-01 21:59:00 +00:00
|
|
|
|
2020-06-11 23:27:21 +00:00
|
|
|
func _draw() -> void:
|
2021-11-25 12:48:30 +00:00
|
|
|
var current_project: Project = Global.current_project
|
2020-09-27 22:09:11 +00:00
|
|
|
if frame >= current_project.frames.size():
|
|
|
|
frame = current_project.current_frame
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
$AnimationTimer.wait_time = (
|
|
|
|
current_project.frames[frame].duration
|
|
|
|
* (1 / Global.current_project.fps)
|
|
|
|
)
|
2020-08-01 21:59:00 +00:00
|
|
|
|
|
|
|
if animation_timer.is_stopped():
|
|
|
|
frame = current_project.current_frame
|
2021-11-25 12:48:30 +00:00
|
|
|
var current_cels: Array = current_project.frames[frame].cels
|
2020-06-11 23:27:21 +00:00
|
|
|
|
|
|
|
# Draw current frame layers
|
|
|
|
for i in range(current_cels.size()):
|
|
|
|
var modulate_color := Color(1, 1, 1, current_cels[i].opacity)
|
2020-06-22 12:57:42 +00:00
|
|
|
if i < current_project.layers.size() and current_project.layers[i].visible:
|
2020-06-11 23:27:21 +00:00
|
|
|
draw_texture(current_cels[i].image_texture, Vector2.ZERO, modulate_color)
|
2020-08-01 21:59:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _on_AnimationTimer_timeout() -> void:
|
2022-07-21 19:26:01 +00:00
|
|
|
var first_frame := 0
|
|
|
|
var last_frame: int = Global.current_project.frames.size() - 1
|
2021-11-25 12:48:30 +00:00
|
|
|
var current_project: Project = Global.current_project
|
2022-07-21 19:26:01 +00:00
|
|
|
|
|
|
|
if Global.play_only_tags:
|
|
|
|
for tag in current_project.animation_tags:
|
|
|
|
if (
|
|
|
|
current_project.current_frame + 1 >= tag.from
|
|
|
|
&& current_project.current_frame + 1 <= tag.to
|
|
|
|
):
|
|
|
|
first_frame = tag.from - 1
|
|
|
|
last_frame = min(current_project.frames.size() - 1, tag.to - 1)
|
|
|
|
|
|
|
|
if frame < last_frame:
|
2020-08-01 21:59:00 +00:00
|
|
|
frame += 1
|
|
|
|
else:
|
2022-07-21 19:26:01 +00:00
|
|
|
frame = first_frame
|
2020-10-19 14:57:40 +00:00
|
|
|
|
|
|
|
$AnimationTimer.set_one_shot(true)
|
2021-11-25 12:48:30 +00:00
|
|
|
$AnimationTimer.wait_time = (
|
|
|
|
Global.current_project.frames[frame].duration
|
|
|
|
* (1 / Global.current_project.fps)
|
|
|
|
)
|
2020-10-19 14:57:40 +00:00
|
|
|
$AnimationTimer.start()
|
2020-08-01 21:59:00 +00:00
|
|
|
update()
|