mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 17:19:50 +00:00
Only plays the portion of the sound that corresponds to the specific frame so maybe we should do that as well
When the animation is not running. If it is running, play the sound properly.
This commit is contained in:
parent
214ba1b17d
commit
710f6d41e6
|
@ -70,16 +70,21 @@ func _on_cel_switched() -> void:
|
|||
z_index = 1 if button_pressed else 0
|
||||
var layer := Global.current_project.layers[layer_index]
|
||||
if layer is AudioLayer:
|
||||
if not is_instance_valid(audio_player):
|
||||
return
|
||||
if not layer.is_visible_in_hierarchy():
|
||||
if is_instance_valid(audio_player):
|
||||
audio_player.stop()
|
||||
elif not animation_running or Global.current_project.current_frame == layer.playback_frame:
|
||||
_play_audio()
|
||||
return
|
||||
if animation_running:
|
||||
if Global.current_project.current_frame == layer.playback_frame:
|
||||
_play_audio(false)
|
||||
else:
|
||||
_play_audio(true)
|
||||
|
||||
|
||||
func _on_animation_started(_dir: bool) -> void:
|
||||
animation_running = true
|
||||
_play_audio()
|
||||
_play_audio(false)
|
||||
|
||||
|
||||
func _on_animation_looped() -> void:
|
||||
|
@ -96,17 +101,21 @@ func _on_animation_finished() -> void:
|
|||
audio_player.stop()
|
||||
|
||||
|
||||
func _play_audio() -> void:
|
||||
func _play_audio(single_frame: bool) -> void:
|
||||
if not is_instance_valid(audio_player):
|
||||
return
|
||||
var layer := Global.current_project.layers[layer_index] as AudioLayer
|
||||
var project := Global.current_project
|
||||
var layer := project.layers[layer_index] as AudioLayer
|
||||
if not layer.is_visible_in_hierarchy():
|
||||
return
|
||||
var audio_length := layer.get_audio_length()
|
||||
var frame := Global.current_project.frames[Global.current_project.current_frame]
|
||||
var frame_pos := frame.position_in_seconds(Global.current_project, layer.playback_frame)
|
||||
var frame := project.frames[project.current_frame]
|
||||
var frame_pos := frame.position_in_seconds(project, layer.playback_frame)
|
||||
if frame_pos >= 0 and frame_pos < audio_length:
|
||||
audio_player.play(frame_pos)
|
||||
if single_frame:
|
||||
var timer := get_tree().create_timer(frame.get_duration_in_seconds(project.fps))
|
||||
timer.timeout.connect(func(): audio_player.stop())
|
||||
else:
|
||||
audio_player.stop()
|
||||
|
||||
|
|
Loading…
Reference in a new issue