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
Thanks for showing the outputs. Sorry for my requests being confusing, I'll try to clarify my requests if next chance.
I wanted to clarify that
- `touchesBegan` is called and finishes execution normally
- Other parts of `touchesBegan` is not affecting the isHidden property
As for now, both clarified, I have no clue where to investigate.
I'll check your code again taking more time, and when I find something (possibly) wrong, I will write a comment about that.