Ios 如何在SpriteKit和SceneKit-SWIFT中暂停游戏

Ios 如何在SpriteKit和SceneKit-SWIFT中暂停游戏,ios,swift,Ios,Swift,我试图通过触摸按钮来暂停我的游戏,但我无法让它工作 我试过这个: pause = SKSpriteNode (imageNamed: "pause.png") pause.size = CGSizeMake(30, 30) pause.position = CGPointMake(30, 30) self.addChild(pause) 我试图调用这样一个函数: func touchesBegin (touches: NSSet!, withEvent event: UIEvent!)

我试图通过触摸按钮来暂停我的游戏,但我无法让它工作

我试过这个:

pause = SKSpriteNode (imageNamed: "pause.png")
pause.size = CGSizeMake(30, 30)
pause.position = CGPointMake(30, 30)
self.addChild(pause)
我试图调用这样一个函数:

func touchesBegin (touches: NSSet!, withEvent event: UIEvent!)   
{

    for touch: AnyObject in touches
    {
        let location = touch.locationInNode(self)
        if self.nodeAtPoint(location) == self.pause
        {
            let skView = self.view as SKView
            skView.paused = true
        }
    }

}
当我按下暂停按钮时,什么也没发生。。。 怎么了


谢谢大家!

我自己解决了这个问题:

下面是我的代码函数:

  override func touchesBegan(touches: NSSet!, withEvent event: UIEvent!) 
  {
    var touch:UITouch = touches.anyObject() as UITouch
    pauseText.text = "Pause"
    pauseText.fontSize = 50
    pauseText.position = CGPointMake(self.frame.size.width/2, self.frame.size.height/2)

                   /* bouton play/pause */

    var locationPause: CGPoint = touch.locationInNode(self)
    if self.nodeAtPoint(locationPause) == self.pause
        {
        addChild(pauseText) // add the text
        pause.removeFromParent ()  // to avoid error when you touch again
        self.runAction (SKAction.runBlock(self.pauseGame))
        }

  }
要继续游戏,只需在最后一个“}”之前添加此代码:

在SKScene子类中,添加此函数以在暂停期间添加标签:

func pauseGame()
    { 
    self.view.paused = true // to pause the game
    }
func pauseGame()
    { 
    self.view.paused = true // to pause the game
    }