Hello! I’m making a rhythm game where I need to keep track of the song position and play a metronome.
Everything works as intended when I run the game locally on my computer, however, when I export it to HTML, AudioServer malfunctions and returns negative.
Weirdest of all, it visually works until I click on the browser to play my game. I also made sure to enable both thread and extension support!
var song_position: float = 0.0
var song_position_in_beats: float = 0
var last_reported_beat: float = 0
var seconds_per_beat: float = 0
func _process(delta: float) -> void:
if music_player.playing:
song_position = music_player.get_playback_position() + AudioServer.get_time_since_last_mix()
song_position -= AudioServer.get_output_latency()
song_position_in_beats = snapped(song_position / seconds_per_beat, 0.1) + beats_before_start
label.text = str(song_position_in_beats)
label_2.text = str(last_reported_beat)
if not _repeating_beat():
_change_color()
func _repeating_beat() -> bool:
if song_position_in_beats == last_reported_beat:
return true
last_reported_beat = song_position_in_beats
return false