Created
September 8, 2022 09:05
-
-
Save hiulit/d8e41f4672a5b0c72c8636a9164d2d72 to your computer and use it in GitHub Desktop.
AudioStreamPlayer with a counter, which counts the seconds elapsed and emits a signal each second
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends AudioStreamPlayer | |
class_name AudioStreamPlayerWithCounter | |
signal playback_position_reached(number) | |
var counter: int | |
var previous_counter: int | |
func _ready() -> void: | |
if not stream: | |
set_process(false) | |
func _process(_delta: float) -> void: | |
counter = int(get_playback_position()) | |
if previous_counter != counter: | |
previous_counter = counter | |
emit_signal("playback_position_reached", counter) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example: