Skip to content

Instantly share code, notes, and snippets.

@hiulit
Created September 8, 2022 09:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hiulit/d8e41f4672a5b0c72c8636a9164d2d72 to your computer and use it in GitHub Desktop.
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
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)
@hiulit
Copy link
Author

hiulit commented Sep 8, 2022

Example:

func _on_AudioStreamPlayerWithCounter_playback_position_reached(number: int) -> void:
	if number == 10:
		# do something

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment