【问题标题】:Sound not Playing on Contact接触时不播放声音
【发布时间】:2014-12-23 19:34:02
【问题描述】:

我有一个简单的游戏,其中一个球跳过障碍物。当它与障碍物接触时(无论是在跳跃时还是在跳跃前碰撞时),我想在过渡到主菜单屏幕(GameScene.Swift)之前播放声音。肯定会检测到 didBeginContact 但不一定会检测到 didEndContact 由于某种原因,声音文件无法播放。我做错了什么?

PlayScene.Swift 文件

class PlayScene: SKScene, SKPhysicsContactDelegate{
    //......
    let losingSoundAction = SKAction.playSoundFileNamed("losing.wav", waitForCompletion: true)
    //....

   func didBeginContact(contact: SKPhysicsContact) {
      //play the losing sound
      self.runAction(losingSoundAction)

      contact.bodyA.categoryBitMask = ColliderType.Hero.rawValue
      died()
   }

   func died(){
      //change back to main screen
      if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene {
         let skView = self.view as SKView!
         scene.scaleMode = .AspectFill
         scene.GameSceneInstance = self
         scene.score = score
         skView.presentScene(scene)
      }
   }
}

【问题讨论】:

  • didBeginContact 是否执行?如果没有,您是否将类设置为物理代理?
  • yes didBeginCONtact 执行,因为场景更改为主 GameScene

标签: ios swift sprite-kit skscene


【解决方案1】:

我将 dead() 函数调用移至 didEndContact() ,这似乎解决了问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-20
    • 2011-02-25
    • 2020-02-15
    相关资源
    最近更新 更多