Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperLicht
Play Sounds from Java Script

codedreamer
Registered User
Quote
2011-12-08 17:12:45

I just bought CopperCube and using it with CopperLicht in the hopes of creating some "educational" games for my boys. I see how to add sounds via CopperCube but would like to manipulate/play/stop those sounds in JavaScript. I have not been able to find any examples...Does anyone have some examples of how you can start and stop sounds that have already been added to the scene via the CopperCube publish to WebGL?

I look forward to really having fun with this engine (and hopefully my boys will too)!

Thanks


codedreamer
Registered User
Quote
2011-12-09 02:48:20

Well I poked around in CopperLicht and this seems to work:

var sound = scene.getSceneNodeFromName("Explosion");
var soundMgr = CL3D.gSoundManager;
soundMgr.play2D(this.sound.TheSound);


W


codedreamer
Registered User
Quote
2011-12-09 02:51:25

Didn't get a chance to finish my last post...


Where "Explosion" is a Sound Node previously created in CopperCube.
How would you handle 3D sound?

Thanks


niko
Moderator
Quote
2011-12-09 07:38:51

Unfortunately, the HTML 5 audio API doesn't allow real 3d sound yet, so currently, it's only a volume change. For 3D sound, you could create the (undocumented) soundSceneNode. Something like this should work (I haven't tried it out)


var s = new CL3D.SoundSceneNode()
s.scene = scene;
s.Visible = true;
s.Position = new CL3D.Vect3d(0,0,0);
s.Rot = new CL3D.Vect3d(0,0,0);
s.Scale = new CL3D.Vect3d(0,0,0);
s.TheSound = someSound;
s.MinDistance = 1.0;
s.MaxDistance = 100.0;
s.PlayMode = 1; // play once, 2 for loop
s.Volume = 1.0;
s.PlayAs2D = false;

scene.getRootSceneNode().addChild(s);



codedreamer
Registered User
Quote
2011-12-09 14:24:26

niko,

Hey thanks! I think we're all very hopeful concerning HTML 5. However, this looks like it'll work for my purposes. I'll try it out and let you know...

Thanks again


codedreamer
Registered User
Quote
2011-12-09 16:33:56

Hmmm, I’m not sure I’m dealing with it correctly but this is what I observed:

I’m not sensing any variability in volume based upon the position of the Sound Node with respect to the active camera position (i.e. player). However, the MaxDistance does significantly affect the volume level – the shorter distance the louder the volume. I assumed the MaxDistance would affect how far away the “player” would be able to detect the sound (i.e. drops off when player is > MaxDistance away from the sound while < MaxDistance the vol is interpolated based upon delta between active camera position and Sound Node position). Does the volume automatically adjust based upon active camera position with respect to sound node position or are my assumptions out in “left field”?

Thanks


niko
Moderator
Quote
2011-12-10 07:40:29

Hm, it works nearly the same way as if you would create the sound node in the editor CopperCube, and there it works, try it out. What could be is that you chose a too big value for Min and Max, try much smaller ones. (for example set both to 20). The fallof is not linear but logarithmic.


mushra
Registered User
Quote
2012-04-24 17:47:58

How do you stop a sound from playing?
I have tried: soundMgr.stop( s.TheSound ); and I get an error.

Thanks


niko
Moderator
Quote
2012-04-24 19:16:50

Hm, did you try soundMgr.stop(s) instead?


mushra
Registered User
Quote
2012-04-26 10:53:59

I tried that ,and still get the same error.

Uncaught TypeError: Cannot read property 'audioElm' of undefinede



niko
Moderator
Quote
2012-04-27 07:49:00

I've now looked into it: that's a bug. Will be fixed in the next update. For now, you can stop sound using this code:


s.src.audioElem.pause();
s.hasStopped = true;
soundMgr.clearFinishedPlayingSounds();



mushra
Registered User
Quote
2012-05-01 01:30:10

I tried that, but I still get the same error.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "?nternational" (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