Hello,
I am making my first game and am running into an issue. I have a pause button in my game and when it's pressed I want my "pauseMenu" to unhide, but it's not working. Here's code from my GameScene:
if touchNode == pauseButton {
pauseGame()
}
func pauseGame() {
self.view?.isPaused = true
print("Before isHidden is set to false: \(pauseMenu?.isHidden)")
pauseMenu?.isHidden = false
print("After isHidden is set to false: \(pauseMenu?.isHidden)")
}
Here's what prints:
Before isHidden is set to false: Optional(true)
After isHidden is set to false: Optional(false)
As you can see, the pauseGame() function gets called successfully, and the view pauses, but the pauseMenu stays hidden. It's weird because it successfully unhides if I call pauseMenu?.isHidden = false elsewhere, like in my function that is called when the game ends:
func gameOver() {
...
toggleViews()
}
func toggleViews() {
...
print("Before isHidden is set to false: \(pauseMenu?.isHidden)")
pauseMenu?.isHidden = false
print("After isHidden is set to false: \(pauseMenu?.isHidden)")
}
This successfuly unhides the pauseMenu and prints the same code:
Before isHidden is set to false: Optional(true)
After isHidden is set to false: Optional(false)
I think the problem has something to do with not being able to hide or unhide something from a touchNode, if I call toggleViews() like this, nothing happens to the gameScene.
if touchNode == pauseButton {
toggleViews()
}
I'm at a loss here, I've been trying to fix this for a few hours. Any help is greatly appreciated