Syncing actions in different scenes to music (or time)

  • #1, by YourichiganTuesday, 03. October 2017, 17:35 7 years ago
    Hello there!

    I have a problem making different actions syncronized in different scenes.

    I have different scenes, in one I start a music file (background music), other scenes have a "continue music from previous scene" checked, so the music is continuous. 

    The music has specific beat, and I need animations/objects in scenes to move, or change opacity at certain times with the music. For example - change opacity of object A to 0% at 12th second since music started or move animation frame by X.Y at 25th second etc. 

    There is no problem to time it in one scene (i just start action for animation and objects at the same time as music starts), but once i start changing scenes, there appears a noticeable delay between music and specific actions. Which is probably due to scene loading time. 

    Is there a way, maybe, to use some global value to syncronize actions?

    I used a value in first scene, that i increment by 1 every 1 second in endless loop, so in other scenes i check that value, and make the action if needed (for example, if value == 12 -> change opacity, and so on). But this does not work, as the value seems to not increment in short period of scene change. And delay is visible after only one scene change. 

    Newbie

    12 Posts


  • #2, by afrlmeTuesday, 03. October 2017, 18:19 7 years ago
    Using the background music is hard because there's no method for accessing the current playback time of the background music & as you say, it seems to pause looping action block when changing to another scene - you could try & offset the time at the beginning of the scene, but I have a feeling that the time will end up differing on each different machine the game is played on.

    What about using Lua & trying out this setDelay function Simon created recently? There's an example of it in action on the right hand side of the page. I'm not 100% sure, but I'm betting you could probably use that to create an incremental loop have it + 1 a variable every 1000ms (1 second). You could use the Lua while loop with it, but I'm not a big fan of the while or repeat until loops as they often cause VS to crash. Maybe could plus one then have it recall the same function to make it repeat thus creating a self-loop without having to rely on mainLoop or any of the other loop types.

    Imperator

    7278 Posts

  • #3, by YourichiganFriday, 06. October 2017, 15:48 7 years ago
    Thanks for reply AFRLme smile 

    The setDelay function does seem to work, but i am still in a process of testing it thorougly. And also there is a problem that it is in VS5.0 only, we did not transit yet from the 4.2.5 version. 

    So i am still looking for ways to do this in 4.2.5 version of editor. And i am out of ideas now roll

    Also, in last sentence you mean a function like:

    function incrementalLoop()
    
    value_to_increment += 1
    
    setDelay(1000, incrementalLoop)
    
    end

    Newbie

    12 Posts

  • #4, by afrlmeFriday, 06. October 2017, 16:09 7 years ago
    Yeah something like that. I think setDelay() is probably a 5.x feature. I made the change a little while back to 5.x. Still have 4.2.5 installed as well though.

    P.S: Also having my own sync problems. I've been trying to get 2 animations to sync without much luck. I have a talk animation that performs hand gesture segments & I've been trying to make it so that if talk animation ends partway through one of those that it will carry on inside of the idle animation as it has the same hand animation in that too, but it's not playing ball for me. roll

    Only thing I can think of for you with 4.2.5 version is using the openAL sound engine with Lua script, but the music cuts out when changing scenes unlike the built in background music option. Maybe you could use a mainLoop handler & use getTime() function to check when time = more than or equal to 1000 then increment a value. The only problem is that over time it will likely lose sync as it's not 100% accurate. It will likely end up being a few ms off each time you reset the getTime() function; then again a few ms here & there will take a while to offset out of sync by a full second or more.

    Maybe worth a try? Here's the getTime() function page with an example on creating a time delay/loop.

    Imperator

    7278 Posts