Background music

  • #1, z dimmarkThursday, 18. April 2013, 12:18 hodinky 12 years ago
    Hallo,

    I would like to add background music which will be the same for some scenes and won't be restatred when then player enters in a new scene.

    Is there any way to do that?

    Thanks for your help

    Bažant

    1 Posts


  • #2, z afrlmeThursday, 18. April 2013, 12:43 hodinky 12 years ago
    you just have to tick the "continue music from the previous scene" check box, in the scene properties tab.

    Imperátor

    7285 Posts

  • #3, z gustySaturday, 20. April 2013, 05:37 hodinky 12 years ago
    And is it possible to make a volume of the music based on the distance? Let say there is a guitarist on the street (one big scrolling scene) and he is playing the guitar. When player stands right in front of him, then the music volume is 100%, but when he starts walking away from the guitarist along the street, then the music volume fading away... and player keeps walking off and music is weaker and weaker... 80%.. 70%.. Do you know what I mean? Is it possible to do so in the Visionaire?

    Fanoušek fóra

    159 Posts

  • #4, z afrlmeSaturday, 20. April 2013, 13:22 hodinky 12 years ago
    yes with Lua Script & mainLoop event handler & then some code to check character position vs object position, which you then have to calculate (somehow) into a percentage.

    I have been working on a dynamic footstep script which defines footstep volume & walk speed based on characters current scale & audio balance based on characters x position on a screen; but this can only really be done in the next release of Visionaire Studio where you have access to the audio Lua commands; amongst other things.

    P.S: I may, at some point add some examples of what can be done with the new
    Lua audio commands for the next release, to the new documentation wiki; stuff like audio panning, fade in/out, executing functions based on current playtime of a sound file etc.

    Imperátor

    7285 Posts

  • #5, z gustySaturday, 20. April 2013, 17:08 hodinky 12 years ago
    Thanks for comment AFRLme, do you have an idea when next release of Visionaire will be out?

    Fanoušek fóra

    159 Posts

  • #6, z afrlmeSaturday, 20. April 2013, 17:14 hodinky 12 years ago
    nope, sorry - not as yet.
    David & Alex are still busy working on things.

    * I will upload an exported demo of what the script does that I've been working on in a little while - just making a few final touches to the script & project file.

    Imperátor

    7285 Posts

  • #7, z gustySaturday, 20. April 2013, 17:17 hodinky 12 years ago
    OK, thanks man! Looking forward to try your demo.

    Fanoušek fóra

    159 Posts

  • #8, z afrlmeSunday, 21. April 2013, 17:06 hodinky 12 years ago
    And is it possible to make a volume of the music based on the distance? Let say there is a guitarist on the street (one big scrolling scene) and he is playing the guitar. When player stands right in front of him, then the music volume is 100%, but when he starts walking away from the guitarist along the street, then the music volume fading away... and player keeps walking off and music is weaker and weaker... 80%.. 70%.. Do you know what I mean? Is it possible to do so in the Visionaire?


    Ok so I have written a new script which plays sounds from the character with the volume based on character scale size (plus/minus a small random value. to add dynamic feel) & audio balance is based on current x position of character in the current camera view point (what you can currently see)

    --[[
    Character sound & property functions (v1.0)
    Written by AFRLme
    -- * --
    label@alternatingfrequencies.com, aim/skype: AFRLme
    --]]
    
    function playCharSound(char, sound)
     local tbl = {} -- create an empty table
     tbl["_temporary_"] = "" -- set table as temporary
     tbl["character"] = getObject("Characters[" .. char .. "]") -- store current character
     tbl["character_size"] = tbl["character"]:getInt(VCharacterSize) -- get linked characters current scale
     tbl["character_pos"] = tbl["character"]:getPoint(VCharacterPosition).x -- get linked characters current x pos
     tbl["random_val"] = math.random(-5, 5) -- for adding/subtracting from sound volume (dynamic reasons)
     tbl["volume"] = tbl["character_size"] + tbl["random_val"] -- adds or subtracts random value from volume level
     tbl["screen_center"] = (game:getPoint(VGameWindowResolution).x / 2) + game:getPoint(VGameScrollPosition).x -- find current scene center x pos
     -- * check if position of character to screen center to determine if audio balance % should be a positive or negative value
     if tbl["character_pos"] < tbl["screen_center"] then tbl["balance"] = - ((tbl["screen_center"] - tbl["character_pos"]) / (game:getPoint(VGameWindowResolution).x / 2) * 100) end -- inverse balance %
     if tbl["character_pos"] >= tbl["screen_center"] then tbl["balance"] = ((tbl["character_pos"] - tbl["screen_center"]) / (game:getPoint(VGameWindowResolution).x / 2) * 100) end -- positive balance %
     -- * break * --
     startSound(tblSounds[sound][1], {flags=1, volume=tbl["volume"], balance=tbl["balance"]})
     -- * debug * --
     --print("character name: " .. char .. ", size: " .. tbl["character_size"] .. ", x pos: " .. tbl["character_pos"])
     --print("volume: " .. tbl["volume"] .. ", original volume: " .. tbl["character_size"] .. ", random value: " .. tbl["random_val"])
     --print("screen center: " .. tbl["screen_center"])
     --print("balance: " .. tbl["balance"] .. "\n")
    end
    

    you need to create a table containing sounds for this to work & it works by executing a script > playCharSound("character_name", "sound_name")
    this won't work in the current version obviously but I thought I would share.

    What you are asking for is somewhat more complicated because we have to take into consideration both the characters x & y position from the object to calculate the volume percentage (%) & as of yet, I have no clue how to calculate this, because I really hate math & I am not very good at it. (it would have to be done with the mainLoop event handler too)

    I wonder if it would be possible to hard code it into the engine itself & have it as an option (will have to ask David later - if I remember)

    * edit: bloody emoticons (no idea why they are being added to the code box itself)

    Imperátor

    7285 Posts

  • #9, z esmeraldaTuesday, 23. April 2013, 17:57 hodinky 12 years ago
    A possible workaround could be to create some action areas in the scene (spaced along the scene) with an action setting the volume at 90%, 80%...
    Just an idea - haven't tried it yet

    Zabiják klíčů

    525 Posts

  • #10, z gustyTuesday, 23. April 2013, 18:00 hodinky 12 years ago
    It sounds like an elegant solution in its theory, I'll definitely try that.

    Fanoušek fóra

    159 Posts

  • #11, z afrlmeTuesday, 23. April 2013, 18:13 hodinky 12 years ago
    it is possible, the way Esmeralda mentioned - a bit more effort involved & somewhat less accurate but very do-able smile

    Imperátor

    7285 Posts