当触摸屏幕时,我的随机AVFoundation声音会让它略微出现故障

时间:2015-08-11 18:11:10

标签: xcode swift sprite-kit avfoundation

我有一个不断流动的游戏,为了让游戏正常播放,帧速率需要零毛刺或断断续续。我有一个从随机选择中拉出的声音,如下所示,所有名为Jump(跳跃是2秒声音),但是当它从随机选择器拉出它时,屏幕上的所有内容都停止了一会儿,然后又回到了它应该是。当一个接受该功能的调用“Jump()”游戏工作正常没有口吃,但当然也没有声音。有谁知道为什么?它的自我是好的声音但它周围的一切就像动画口吃是否有更好的方法在SpriteKit中导入声音?

代码:

      class SecondScene: SKScene, SKPhysicsContactDelegate {

    var JumpURL = NSURL(fileURLWithPath:    NSBundle.mainBundle().pathForResource("JustThePopinCutOffJump", ofType:   "mp3")!)
     var Jump = AVAudioPlayer()
      var Jump1URL = NSURL(fileURLWithPath:  NSBundle.mainBundle().pathForResource("JustThePopinCutOffJump", ofType: "mp3")!)
       var Jump1 = AVAudioPlayer()
     var Jump2URL = NSURL(fileURLWithPath:   NSBundle.mainBundle().pathForResource("JustThePopinCutOffJump", ofType: "mp3")!)
     var Jump2 = AVAudioPlayer()
     var Jump3URL = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("JustThePopinCutOffJump", ofType: "mp3")!)
var Jump3 = AVAudioPlayer()
var Jump4URL = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("JustThePopinCutOffJump", ofType: "mp3")!)
var Jump4 = AVAudioPlayer()
var Jump5URL = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("JustThePopinCutOffJump", ofType: "mp3")!)
var Jump5 = AVAudioPlayer()
var Jump6URL = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("JustThePopinCutOffJump", ofType: "mp3")!)
var Jump6 = AVAudioPlayer()
var Jump7URL = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("JustThePopinCutOffJump", ofType: "mp3")!)
var Jump7 = AVAudioPlayer()
var Jump8URL = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("JustThePopinCutOffJump", ofType: "mp3")!)
var Jump8 = AVAudioPlayer()
var Jump9URL = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("JustThePopinCutOffJump", ofType: "mp3")!)
var Jump9 = AVAudioPlayer()
var Jump10URL = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("JustThePopinCutOffJump", ofType: "mp3")!)
var Jump10 = AVAudioPlayer()
var Jump11URL = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("JustThePopinCutOffJump", ofType: "mp3")!)
var Jump11 = AVAudioPlayer()
var Jump12URL = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("JustThePopinCutOffJump", ofType: "mp3")!)
var Jump12 = AVAudioPlayer()


   override func didMoveToView(view: SKView) {

     Jump = AVAudioPlayer(contentsOfURL: JumpURL, error: nil)
    Jump.volume = 0.10
    Jump1 = AVAudioPlayer(contentsOfURL: JumpURL, error: nil)
    Jump1.volume = 0.10
    Jump2 = AVAudioPlayer(contentsOfURL: JumpURL, error: nil)
    Jump2.volume = 0.10
    Jump3 = AVAudioPlayer(contentsOfURL: JumpURL, error: nil)
    Jump3.volume = 0.10
    Jump4 = AVAudioPlayer(contentsOfURL: JumpURL, error: nil)
    Jump4.volume = 0.10
    Jump5 = AVAudioPlayer(contentsOfURL: JumpURL, error: nil)
    Jump5.volume = 0.10
    Jump6 = AVAudioPlayer(contentsOfURL: JumpURL, error: nil)
    Jump6.volume = 0.10
    Jump7 = AVAudioPlayer(contentsOfURL: JumpURL, error: nil)
    Jump7.volume = 0.10
    Jump8 = AVAudioPlayer(contentsOfURL: JumpURL, error: nil)
    Jump8.volume = 0.10
    Jump9 = AVAudioPlayer(contentsOfURL: JumpURL, error: nil)
    Jump9.volume = 0.10
    Jump10 = AVAudioPlayer(contentsOfURL: JumpURL, error: nil)
    Jump10.volume = 0.10
    Jump11 = AVAudioPlayer(contentsOfURL: JumpURL, error: nil)
    Jump11.volume = 0.10
    Jump12 = AVAudioPlayer(contentsOfURL: JumpURL, error: nil)
    Jump12.volume = 0.10

      func PlayCheeringEffect() {

CheeringEffect.play()

}

func PlayJumpEffect() {

Jump.play()

}
func PlayJump1Effect() {

    Jump1.play()

}
func PlayJump2Effect() {

    Jump2.play()

}
func PlayJump3Effect() {

    Jump3.play()

}
func PlayJump4Effect() {

    Jump4.play()

}
func PlayJump5Effect() {

    Jump5.play()

}

func PlayJump6Effect() {

    Jump6.play()

}
func PlayJump7Effect() {

    Jump7.play()

}
func PlayJump8Effect() {

    Jump8.play()

}
func PlayJump9Effect() {

    Jump9.play()

}
func PlayJump10Effect() {

    Jump10.play()

}
func PlayJump11Effect() {

    Jump11.play()

}
func PlayJump12Effect() {

    Jump12.play()

}



  override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {


    func randomjump() {
    let randompick = rand() % 12;
    switch (randompick) {
    case 0:
        Jump.play()
        break;
    case 1:
        Jump1.play()
        break;
    case 2:
        Jump2.play()
        break;
    case 3:
        Jump3.play()
        break;
    case 4:
        Jump4.play()
        break;
    case 5:
        Jump5.play()
        break;
    case 6:
        Jump6.play()
        break;
    case 7:
        Jump7.play()
        break;
    case 8:
        Jump8.play()
        break;
     case 9:
        Jump9.play()
        break;
     case 10:
        Jump10.play()
        break;
     case 11:
        Jump11.play()
        break;
    default: Jump12.play()
        break;
      }
     }

    randomjump()

0 个答案:

没有答案