Jump to content

Sound with ActionManager.RegisterAction


hit2501
 Share

Recommended Posts

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?.

Link to comment
Share on other sites

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 using

var audio = new BABYLON.Sound("Fire", "Fire.wav", scene, null, { loop: true, autoplay: false });

To combine animation and play sound, just do

myMesh.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 !

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...