boyofgreen 7 Report post Posted April 19, 2016 Hi, I'm working on a project where I have a timeline. The visual part is quite easy because I keep an external array of key frame to push into my aimations. I'd like to do the same thing with the sound files, so if I user decides they want to play a sound 2 seconds into the scene, I can time it right with the animations. Currently, I'm maintaining an external array, and an external frame counter, that looks like this: var keyFrame = 0; timer = setInterval(collectData, 500 / kps); //keys per second var collectData = function(){ if(isRecording === true){ var character = {}; character.keyFrame = keyIndex; character.x = currentCharacter.plane.position.x; character.y = currentCharacter.plane.position.y; // currentCharacter.characterPath.push(character); currentCharacter.characterPath[keyIndex] = character; //these paths are pushed into Babylon animations } keyIndex++; }; for audio, I am basically keeping a separate array with code that does something like this: var soundArray = [...]; scene.registerBeforeRender(function(){ //check to see if the keyIndex is mateches any of the frames soundArray.forEach(function(el){ if(frame === keyIndex){ sound.play() } }) }); my question, is there any more efficient way to have the scene play the sound, rather than managing it externally? Quote Share this post Link to post Share on other sites
Deltakosh 4315 Report post Posted April 19, 2016 This question is definitely for @davrous:) Quote Share this post Link to post Share on other sites
boyofgreen 7 Report post Posted April 20, 2016 Unless there is a better suggestion, I think I found the answer: http://doc.babylonjs.com/tutorials/Animations#attach-events-to-animations looks like I can add events to the animation that will fire the audio. I' open to better ideas if there are any. 1 meteoritool reacted to this Quote Share this post Link to post Share on other sites
Deltakosh 4315 Report post Posted April 20, 2016 You nailed it! Quote Share this post Link to post Share on other sites