In order to make a pause in a SpriteKit game I made a pause button. It worker like a charm when I wanted to make an another scene for pause and respond to touch was transitioning to a scene. My function then looked like this (P.S. pause
= pause button) But there were other problems with it and I decided to make pause within my main scene: playscene
So I added a pauseBackground
and resumeButton
that is attached to pause background and hided it (declared resumeButton.hidden = true
)
Now my function looks like this:
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
if self.onGround {
self.speedY = -20.0
self.onGround = false
}
for touch: AnyObject in touches {
let location = touch.locationInNode(self)
if self.nodeAtPoint(location) == self.pause {
self.scene?.view?.paused = true
self.pauseBackground.hidden = false
self.resumeButton.hidden = false
if self.nodeAtPoint(location) == self.resumeButton {
self.pauseBackground.hidden = true
self.resumeButton.hidden = true
self.scene?.view?.paused = false
}
}
}
}
It's interesting because it worked with scene transitions, but now Xcode can't detect or ignore my tap in pause button location. I don't really know why. Could you please help me? Update: I tried switch statement:
for touch: AnyObject in touches {
let location = touch.locationInNode(self)
switch self.nodeAtPoint(location) {
case self.pause:
self.scene?.view?.paused = true
self.pauseBackground.hidden = false
self.resumeButton.hidden = false
case self.resumeButton:
self.pauseBackground.hidden = true
self.resumeButton.hidden = true
self.scene?.view?.paused = false
default:
println()
}
}
Sadly, it's not working either! I really have no idea why it's not detecting a touch in that location.