Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
Volume adjustment

astronomical
Registered User
Quote
2019-08-07 14:19:57

Hey,

Is it possible to make sounds played in the engine higher or lower in volume with scripting? Fading sound in and out is ideally what I'm looking for.

Any help would be amazing.


astronomical
Registered User
Quote
2019-08-15 00:10:10

anyone? haha




srfstudio
Registered User
Quote
2019-08-15 14:31:02

I don't think my input will be of much help because I only use *system.soundvolume variable but here it is:
I have musicvolume variable that I use when I have to fade out currently playing music file & fade in new music theme. So for 'fade out' is 1 and for 'fade in' is 2, if 0 than nothing happens.

This is code for fading out placed in 'Every Few Seconds Do Something', *system.soundvolume goes from what ever currant value is to 0:
var musicvol = ccbGetCopperCubeVariable("*system.soundvolume");

if(musicvol > 0)
{ccbSetCopperCubeVariable("*system.soundvolume", Number(musicvol-10));}
else
{ccbSetCopperCubeVariable("musicvolume", 0);}
The * symbol is hashtag that forum always deletes from posts :)


doomtucan
Registered User
Quote
2019-08-22 19:43:28

is it possible to make it so that my players can set the volume for music and game SFX indavidually using varriables and if so how would i do that?


doomtucan
Registered User
Quote
2019-08-26 00:31:25

okay i know i can do both using system.soundvolume using variables but is there a seporate one for just game sound effects cause i cant find no documentation on that cause i want players to be able to adjust both at the lesuire


Robo
Guest
Quote
2019-08-27 04:16:53

No such ability in CC currently.
I have thought to implement the same just like the dev's game 'Post Collapse' has actually but he coded it in C++, not javascript so maybe different.

I believe there is javascript code to do this however and so just add a separate variable to distinguish sound effects to music and maybe use a percentage so you just multiply the variable to each sound effect in each sound code.

That should work.


Robo
Guest
Quote
2019-09-18 09:27:13

Robo wrote:
No such ability in CC currently.
I have thought to implement the same just like the dev's game 'Post Collapse' has actually but he coded it in C++, not javascript so maybe different.

I believe there is javascript code to do this however and so just add a separate variable to distinguish sound effects to music and maybe use a percentage so you just multiply the variable to each sound effect in each sound code.

That should work.


I thought the code existed somewhere to adjust sounds vs music separately yet I cannot get anything to work...perhaps its not possible.
Has anyone else found a solution to this ?


bracer
Registered User
Quote
2019-09-18 18:42:10

While we are at it:
stopAllSounds();
Would be great [access via script, I know it is possible in the IDE].


bracer
Registered User
Quote
2019-09-18 19:18:06

In the meantime, you should all be aware of this audio bug in CopperCube:
ccbPlaySound doesn't work in webgl but works in *.exe.
I tried to copy the *.ogg file inside the copperlichtdata folder to see if that helps but it doesn't.

Screenshot:
https://i.imgur.com/JzSKjjg.png

Now the Action inside the IDE itself works but the JavaScript equivalent "ccbPlaySound" doesn't.

Now it should be noted that since Coppercube's ccbPlaySound doesn't work in browsers, the HTML 5 way of doing it is extremely easy anyway:

var sndSound = new Audio();
sndSound.src = "ByYourSide.ogg";
sndSound.play();

I just want to know if this is an actual bug or it's a known thing and not a bug that ccbPlaySound doesn't work in WebGL, thanks.

PS: Incase someone is thinking "Oh it is a hosted issue, you must run the site through a server for the sound to load if you want to use ccbPlaySound in WebGL" I can assure you, I tested:
var sndSound = new Audio();
sndSound.src = "ByYourSide.ogg";
sndSound.play();
Pure HTML 5 code without running off a hosted server and it works perfectly so there is something really wrong with ccbPlaySound for WebGL.


Robo
Guest
Quote
2019-10-26 14:36:16

astronomical wrote:
Hey,

Is it possible to make sounds played in the engine higher or lower in volume with scripting? Fading sound in and out is ideally what I'm looking for.

Any help would be amazing.


Dang - I worked it out.
The code is not shown as part of the list of available options in CC yet it works and can be used to fade sounds in/out:

Attach two 3D sound nodes to your player - name one 'music' and the other 'soundFx'

You can now dynamically change the volume of either the music or sound effects in game using javascript:

var vol = 50; // 0 -100 volume selection
var s = ccbGetSceneNodeFromName("music"); // a 3D sound node attached to Player as a 2D sound
var sound = "sounds/attack1.ogg" // fixed location of sounds directly under CopperCube directory
ccbSetSceneNodeProperty(s, "SoundFileName", sound);
ccbSetSceneNodeProperty(node, "PlayMode", "play_once");
ccbSetSceneNodeProperty(s, "Volume",vol);

for music either select "play_once" or "looping". If select play_once then you need to change to "nothing" then back to "play_once" to play anything again..


carlosm
Registered User
Quote
2019-11-12 22:34:51

I posted an idea .. here yesterday I came to read if solution for the child volume in ccb.
and I just didn't find what to suggest!

deleted? I broke some forum rule I do not understand.


just_in_case
Moderator
Quote
2019-11-16 04:24:26

i don't know what you are trying to say, assuming if you want to have control over the child node's volume then you can easily do with ccbgetchildnodecount and then changing the volume variable for that node .

or plz if you can explain your idea more clearly.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "In?ernational" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact