2020-06-11 23:27:21 +00:00
|
|
|
extends Node2D
|
|
|
|
|
|
|
|
|
2020-08-01 21:59:00 +00:00
|
|
|
var frame : int = 0
|
|
|
|
onready var animation_timer : Timer = $AnimationTimer
|
|
|
|
|
2020-06-11 23:27:21 +00:00
|
|
|
func _draw() -> void:
|
|
|
|
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
|
|
|
|
|
2020-10-19 14:57:40 +00:00
|
|
|
$AnimationTimer.wait_time = Global.current_project.frame_duration[frame] * (1 / Global.animation_timeline.fps)
|
2020-08-01 21:59:00 +00:00
|
|
|
|
|
|
|
if animation_timer.is_stopped():
|
|
|
|
frame = current_project.current_frame
|
2020-06-11 23:27:21 +00:00
|
|
|
var current_cels : Array = current_project.frames[frame].cels
|
|
|
|
|
|
|
|
# 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:
|
|
|
|
var current_project : Project = Global.current_project
|
|
|
|
if frame < current_project.frames.size() - 1:
|
|
|
|
frame += 1
|
|
|
|
else:
|
|
|
|
frame = 0
|
2020-10-19 14:57:40 +00:00
|
|
|
|
|
|
|
$AnimationTimer.set_one_shot(true)
|
|
|
|
$AnimationTimer.wait_time = Global.current_project.frame_duration[frame] * (1 / Global.animation_timeline.fps)
|
|
|
|
$AnimationTimer.start()
|
2020-08-01 21:59:00 +00:00
|
|
|
update()
|