Jump to content

playing Audio on key frames


Recommended Posts


  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

for audio, I am basically keeping a separate array with code that does something like this:

var soundArray = [...];
//check to see if the keyIndex is mateches any of the frames

if(frame === keyIndex){




my question, is there any more efficient way to have the scene play the sound, rather than managing it externally?



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.

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.


  • Recently Browsing   0 members

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