spritekit暂停按钮不显示

时间:2019-02-25 18:17:10

标签: ios swift sprite-kit

我正在为Spritekit游戏创建一个暂停功能,但是暂停按钮不会显示,我将暂停精灵放入自己的资源中,甚至查看了教程中的暂停按钮,但没有任何内容。

func createPauseButton() {
    pauseButton = SKSpriteNode(imageNamed: "pausebutton")
    pauseButton.size = CGSize(width:40, height:40)
    pauseButton.position = CGPoint(x: self.frame.width - 30, y: 30)
    pauseButton.zPosition = 6
    self.addChild(pauseButton)
}

override public func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    createPauseButton()
    for touch in touches {
        let location = touch.location(in: self)

        if pauseButton.contains(location) {
            if self.isPaused == false  {
                self.isPaused = true
                self.pauseButton.texture = SKTexture(imageNamed: "play")
            } else {
                self.isPaused = false
                self.pauseButton.texture = SKTexture(imageNamed: "pausebutton")
            }
        }
    }
}

0 个答案:

没有答案