The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

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():"walking")

func _process(delta):
    if music_stream.get_playback_position > 2.0 and Input.is_action_pressed("ui_accept"):

I'm using Godot version 3.0.3.

in Engine by (3,164 points)

1 Answer

0 votes

I'm pretty sure it's due to the different delta times between your two PCs. So maybe you can use an event (signal) triggered when the player presses a specific input.

by (178 points)
edited by

Thank you for the response, ZacB. The thing is, the animation and music are almost independent from the user input. Rather, the user responds to the music and animation, and then some other event happens.

Like a PianoTiles game or Guitar Hero ?

Yes, something like that.

I think u can use a custom event.

That's what I eventually ended up doing. It took me a couple of tries, but I eventually settled on a custom countdown timer scene which fired off a signal that, in turn, executed a function in the main node's script. That starts off the mini game, and keeps both the animation and music in synchronization with each other.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.