boyofgreen Posted April 19, 2016 Share 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 Link to comment Share on other sites More sharing options...
GameMonetize Posted April 19, 2016 Share Posted April 19, 2016 This question is definitely for @davrous:) Quote Link to comment Share on other sites More sharing options...
boyofgreen Posted April 20, 2016 Author Share 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. meteoritool 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 20, 2016 Share Posted April 20, 2016 You nailed it! 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.