Godot Version
4.4.1v
Question
I’ve already made the sprite loop three times, and I want the audio to repeat three times to match it. how can i do this?
4.4.1v
I’ve already made the sprite loop three times, and I want the audio to repeat three times to match it. how can i do this?
One thing I noticed is that your signal, animation_finished(), is not actually connected with the _on_call_finished() function. If looping is enabled in your animation, you can use the animation_looped() signal and connect it to a function. Once connected, you can use this code to check how many times it looped and to play the AudioStreamPlayer every time it loops:
func _on_animation_looped():
if repeat_count < max_repeats:
repeat_count += 1
play("call")
$AudioStreamPlayer.play()
else:
var new_scene = load("res://scene/selectscene.tscn")
get_tree().change_scene_to_packed(new_scene)
Try this and see if it works!
Replace the func _on_call_finished() function block with that and connect the animation_looped signal to the new function. To connect a signal, add this in your func _ready():
animation_looped.connect(_on_animation_looped)
I am assuming that this script is attached to your AnimatedSprite2D, and your call animation is set to loop, right?
Seems like the same issue as this thread no? How to play sound matching a sprite - #13 by user85
You stated that you did not get any error when re-running the game but did my solution work? Here mrdicerack is explaining the same solution, childing an AudioStreamPlayer and using $AudioStreamPlayer.play().
Make sure to paste code instead of screenshots
Sorry for the late reply
I took your advice and changed the code
but now the animation only works once and there is no audio.
Please let me know if I changed anything wrong
Check your call animation if loop is enabled, and then remove the play("call") from the _on_call_looped.
Oh, make the AudioStreamPlayer a child of the AnimatedSprite2D, just like what @gertkeno said. Just drag the AudioStreamPlayer to the AnimatedSprite2D.
it works! it works!! it works!!! thank you ![]()
You’re welcome! ![]()
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.