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)