Strategy to sync sound and text

Hi!

I asked this question about sound callbacks some days ago
( Sound callback (text and sound sync) )

I need to sync dialog with text.

I’ve never done that in a game before and the only solution I see is to hardcode all the timestamps when I want to switch text and change a GUI node when the game passes these timestamps.

1) Is this the best way to do it? This implementation feels a bit naive…

2) If the game is running on a slow machine and the sound interrupts because of performance, will the sound continue right where it was interrupted or will it jump past the time-period where the game lagged and continue at the timestamp it would be at if there was no lag?

Yes, I think that’s the way I should have done it as well. If there’s an issue with performance or a hitch of some kind then it will affect not only the sound but the entire engine.

1 Like

I’ve tried and it doesn’t seem to work that well.

I use GAME_TIME=GAME_TIME+dt to keep track of the game time and the subtitles come in at different points in Chrome and Safari relatively to how far the sound track has come:(

Is GAME_TIME=GAME_TIME+dt the way to keep track of time?

I think I solved it.

I printed out dt on screen in both Safari and Chrome and it was constant and the same in both.
Which was strange because the time clearly passed faster in Chrome.

In game.project I found that variable_dt wasn’t checked.

Why isn’t it checked by default? Is it better performance-wise if it’s left unchecked so Defold doesn’t need to recalculate it each time?

I’m not sure why it’s not checked by default. I guess sometimes you prefer to have a constant dt and sometimes you prefer a variable dt. You could also build your text syncing system around something other than dt, for instance os.time() (full seconds only) or socket.gettime() (millisecond precision).

1 Like