How do I get audio and graphics to stay synced (aka rhythm game)

1 favourites
  • 7 posts
From the Asset Store
Sync animations, animation frames, mirror state, sounds and anything else using these methods.
  • So I'm trying to create a rhythm game but can't get it to work properly. I searched the forum and seems people have had issues with before. I looked at the example files (the rhythm game ones), and I'm using the same method.

    Basically, I have audio playing that is exactly 9.6 seconds long, set to looping. Alongside this I have a graphical object that rotates using a tween so it does 360 in 2.4s (1 bar), also looping. It works at first, but after a few minutes it starts to drift and eventually goes out of sync, and I've tried everything to get it to work. I tried resetting the tween so a new one is created each 2.4 instead of 1 continuously loop, or the tween restarting each time the music file loops, but to no avail.

    I also tried having several separate audio tracks play at the same time, but they remain in perfect sync.

    Basically, is there a reliable way to move an object in sync with audio, for longer times?

  • A minimal example project would be really helpful here.

    I'd guess you were building up rounding errors from your various loops, but you said you also reset the tween based on the audio trigger so that doesn't track. That's what I would have recommended, rather than looping and timing everything separately so that they align, pick one thing to base/sync everything else to.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Well, I discovered it during global game jam this weekend, that game can be played here, it had the mechanic I’m describing: jm-j.com/bubblewave

    Granted, that one has multiple things happening which might eventually cause things to get out of sync, I’ll post a simplified example later. That said, I guess what I’m looking for is a way to reliably “reset” things to keep them in sync, or a method that just keeps things in sync. In other engines when I’ve made rhythm games I’ve moved stuff using deltatime and that works, but I haven’t figured out how to do that in Construct yet. I figured the tween function should have been a good equivalent of that.

  • There are a lot of factors in play which could cause this. First of all, make sure that your sound is exactly 9.6 seconds long. Then check your Audio Output Latency, since that plays a role in these situations.

    Even then, as oosyrag suggests, it seems that you're building up errors over time. I tried setting up a small project and I notice the problem too.

    A solution which seems to be working is to calculate the difference between the expected playback time of the sound and the actual playback time, and use that difference to slow down / speed up the tween so that it is always synced.

    Give it a try: dropbox.com/scl/fi/sc8ehxu0njhg8lfs3cin0/Sound-issue-fix.c3p

  • Oh, and I’ve used a global value that everything in the game syncs to, a global value, “beat” (in this case 2.4 since the track is in 100bpm). So start of frame, loops start playing, and the tween starts, moving using said “beat”.

  • Thank you BigBuckBunny, will try it when I get home!

    And yes, the track is exactly 9.6, down to the millisecond.

  • I adapted the solution to my game, and it does indeed appear to solve the problem. Thanks again BigBuckBunny!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)