title: Sprite Kit Animation timed to various sound files - GOAL: animation auto ends at end of each sound file to avoid manually timing each one
body: <p><strong>Hello! First question ever asked here!</strong></p>
  <p>I have a SpriteKit project with a variety of characters and sounds.</p>
  <p>The characters are animated to a whole mess of varying sounds based on the scenes.</p>
  <p>I am trying to find a way that the animations will end when the sound file completes playing. Currently I am using the following setup which would involve manually calculating the count for each scenario.</p>
  <pre><code>func animateCharacter() {
         
          let soundAction = SKAction.playSoundFileNamed(&quot;sound&quot;, waitForCompletion: false)
          let animateAction = SKAction.repeat(SKAction.animate(with: animatedFrames, timePerFrame: 0.1, resize: false, restore: true), count: 3)
          
          character.run(SKAction.sequence([soundAction,animateAction]))
          
          }
  </code></pre>
  <p>Is there any way to automate this so that each animation repeats for the length of each sound file?</p>
  <p>I've tried using repeatForever along with removeAllActions - but that didn't seem to work?</p>
  <p>I'm pretty green here but I'm guessing a type of completion handler based on audio file length?</p>
  <p>Please help.</p>
  <p>Thanks!</p>
  <p>Brought to you by Carl's Jr.</p>