hit2501 Posted February 18, 2015 Share Posted February 18, 2015 Hello. How can I play a BABYLON.sound with a ActionManager.RegisterAction? For animations I use: var obj1 = scene.getMeshByName("Solid"); var obj2 = scene.getMeshByName("Curtains"); var obj3 = scene.getMeshByName("Fire"); obj3.actionManager = new BABYLON.ActionManager(scene); obj3.actionManager.registerAction( new BABYLON.CombineAction(BABYLON.ActionManager.OnPickTrigger, [ new BABYLON.PlayAnimationAction(BABYLON.ActionManager.NothingTrigger, obj1, 0, 100, 0), new BABYLON.PlayAnimationAction(BABYLON.ActionManager.NothingTrigger, obj2, 0, 100, 0) ]) );And for sound: var audio = new BABYLON.Sound("Fire", "Fire.wav", scene, null, { loop: true, autoplay: true });But I dont know how to play the sound at the same time with animations. Can anybody help me please?. Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted February 18, 2015 Share Posted February 18, 2015 Do not know, but try instancing sound (turn off loop and auto play) on line 4. Put a .play() an ExecuteCodeAction as the first element of the array. Would not put the instancing of sound in ExecuteCodeAction, since it needs time to load. Quote Link to comment Share on other sites More sharing options...
hit2501 Posted February 18, 2015 Author Share Posted February 18, 2015 Thanks JC.I tried, dont load and the console gives me: Uncaught SyntaxError: Unexpected token new Quote Link to comment Share on other sites More sharing options...
iiceman Posted February 18, 2015 Share Posted February 18, 2015 Might a execute code action be the right choice here to combine animation and sound? BABYLON.ExecuteCodeAction: Execute your own code when the trigger is raised and the condition is true:ExecuteCodeAction(trigger, func, condition) http://doc.babylonjs.com/page.php?p=22531 Quote Link to comment Share on other sites More sharing options...
julien-moreau Posted February 19, 2015 Share Posted February 19, 2015 Hey, The PlaySoundAction is undocumented, this is my fault.I'm going to ! To play a sound using Action Manager, you can use :obj3.actionManager.registerAction(new BABYLON.PlaySoundAction(BABYLON.ActionManager.OnPickTrigger, soundReference, condition));The soundReference parameter is the sound you already loaded usingvar audio = new BABYLON.Sound("Fire", "Fire.wav", scene, null, { loop: true, autoplay: false });To combine animation and play sound, just domyMesh.actionManager.registerAction( new BABYLON.CombineAction(BABYLON.ActionManager.OnPickTrigger, [ new BABYLON.PlayAnimationAction(BABYLON.ActionManager.NothingTrigger, obj1, 0, 100, 0), new BABYLON.PlaySoundAction(BABYLON.ActionManager.NothingTrigger, mySoundReference) ]));Hope it helps you ! Dad72 1 Quote Link to comment Share on other sites More sharing options...
hit2501 Posted February 20, 2015 Author Share Posted February 20, 2015 Thank you very much Luaacro thats what Ive been looking for. Perhaps I was using this (JC sorry if I dont understood before):obj3.actionManager = new BABYLON.ActionManager(scene); obj3.actionManager.registerAction( //do many actions on Pick trigger (for instance) new BABYLON.CombineAction(BABYLON.ActionManager.OnPickTrigger, [ new BABYLON.PlayAnimationAction(BABYLON.ActionManager.NothingTrigger, obj1, 0, 100, 0), new BABYLON.PlayAnimationAction(BABYLON.ActionManager.NothingTrigger, obj2, 0, 100, 0), new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPickTrigger, function () { var audio = new BABYLON.Sound("Fire", "Fire.wav", scene, null, { loop: true, autoplay: true }); BABYLON.Engine.audioEngine.setGlobalVolume(1); audio.play(); }) ]) ); obj1.actionManager = new BABYLON.ActionManager(scene); obj1.actionManager.registerAction( //do many actions on Pick trigger (for instance) new BABYLON.CombineAction(BABYLON.ActionManager.OnPickTrigger, [ new BABYLON.PlayAnimationAction(BABYLON.ActionManager.NothingTrigger, obj1, 100, 200, 0), new BABYLON.PlayAnimationAction(BABYLON.ActionManager.NothingTrigger, obj2, 100, 200, 0), new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPickTrigger, function () { var audio = new BABYLON.Sound("Fire", "Fire.wav", scene, null, { loop: false, autoplay: false }); BABYLON.Engine.audioEngine.setGlobalVolume(0); }) ]) ); obj3 to start the animations and audio and obj1 to stop the audio, but to stop the audio "audio.stop();" dont work at all, thats the reason I was changing the volume with "BABYLON.Engine.audioEngine.setGlobalVolume" Is there anyway I can stop the audio using Action Manager? Once more thank you Luaacro. Quote Link to comment Share on other sites More sharing options...
julien-moreau Posted February 20, 2015 Share Posted February 20, 2015 Of course you can There is the StopSoundAction that takes the same parameters as PlaySoundAction :var stopSoundAction = new BABYLON.StopSoundAction(BABYLON.ActionManager.OnPickTrigger, soundReference, condition);I'm happy to help you Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.