Question: how can I synchronize music and a piece of animation?
I have a game where the music and animation must be perfectly synchronized (or at least, almost perfectly). This is for a game where tapping to the beat is one of the main mechanics.
I have a script which starts the two pieces of media in the _ready()
function, and monitor them in the _process()
function. While this works just fine on my desktop computer, it doesn't work so well on my laptop. I'm not entirely sure why it's slower on my laptop. It could be due to the music loading (it's an OGG file).
Here's a sample of my striped down code.
extends Node2D
onready var music_stream = $AudioStreamPlayer
onready var animation_stream = $AnimationPlayer
func _ready():
music_stream.play()
animation_stream.play("walking")
func _process(delta):
if music_stream.get_playback_position > 2.0 and Input.is_action_pressed("ui_accept"):
load_next_scene()
I'm using Godot version 3.0.3.