License from €75 Log in
DE EN FR ES IT CZ

Two questions about the stop and resume the background music

This thread is a few years old. Some details may refer to an earlier version of Visionaire Studio. Current tutorials

  1. · 11 years ago
    Hello,

    I have two question about the stop and resume the background music

    In my room 1, I put a radio that broadcasts background music.

    I use this music via the "Background music" function (this is important because I use lua script that allows me to reduce the volume of my music when the character speaks)

    If the player turns off the radio, the music stop (with stop Currently playing sound)

    But, if the music continues to play where the player go in the next room, I will wish that the music continues without interruption (I just change my volume of the music to give the impression that sound is coming from the other room)

    So I search :

    1) how to start and stop a background music in lua
    2) how to make a "continue music from the previous scene" in lua

    Thank in advance
  2. Working on a game?

    The free version covers up to 25 scenes per project. For more scenes and to sell your game, you need a license.

    See licenses Try it for free
  3. · 11 years ago
    I believe I actually wrote a script a while ago for controlling the background music for someone else - don't remember who though, or when - ah wait... scrap that. I wrote it for Simon_ASA for his Catyph / ASA games I think.

    It's not quite what you are asking for though as we wrote it to randomly assign an audio file out of a table to the background music for each scene & to play until the track ended & then it would automatically unload the background music file & call a pause function with a random time interval to delay between playing the next random background audio file. In the script we also checked at the end of a scene if a background music file was currently assigned & if so then we set the next scenes background file to be the same one, thus allowing the music to continue playing seamlessly into the next scene.

    Long story short... avoid using the "continue music from previous scene" option as it's (for lack of a better word) shit. What you want to do is manually add the same file as the background music sound. The engine will automatically continue playing the music into the next scene if it detects that it is the same file.

    Quick note #1: you can not pause & resume background music files or sounds started via the editor in general. The only way to dynamically control the playback position is through sounds started via the Lua startSound() function, however they will not continue seamlessly between scenes & will most likely quit when changing scene.

    game.CurrentScene.BackgroundMusic = "relative_path_to_sound/some_file.ogg" -- set a new background sound.
    game.CurrentScene:clearLink(VSceneBackgroundMusic) -- remove background sound (set empty)
    


    Quick note #2: If you wanted the music to appear as if it is continuing then you could simply mute or fade the scene background music volume in or out using Lua script & the to() tweening function.

    game.CurrentScene:to(100, {MusicVolume = 0}) -- fade music volume for current scene out over 100ms
    game.CurrentScene:to(100, {MusicVolume = 100}) -- music volume for current scene back in over 100ms
    


    Anyway... hope this all helps a wee bit.

    P.S: sorry for the long post.
  4. · 11 years ago
    Hello. Thank you

    I'm very happy, it's working :p you are the best !
  5. · 11 years ago
    No problem at all mate. wink

This thread is closed because nobody has replied for more than a year. Feel free to ask your question in a new thread.

New thread

Really delete this post?