I created my first simple IOS game and created to Layers the gameLayer with my game and a pauseLayer with a resume Button/Node. In my gameLayer I have a button to pause the game and in my pauseLayer a Button/Node to resume. I did this like that in my function that gets points from the touchesEnded function:
var ispaused = false
func touchend(atPoint pos : CGPoint) {
if ispaused == false && pausebutton.contains(pos) {
pauseLayer.isHidden = false
view?.isPaused = true
ispaused = true
}
if ispaused == true && resumebutton.contains(pos) {
pauseLayer.isHidden = true
view?.isPaused = false
ispaused = false
}
}
Everything is working besides that I cant see my resume Button. I can click where it should be and the game resumes. But when I delete the line view?.isPaused = true
the button is displayed as it should be.
This gave me the idea that the pausing view might also pause the process of loading/displaying my resume Button. How can I avoid this problem?
Well to test out your theory of it not loading quick enough.
You can delay code execution with this:
let delayDuration:Double = 1.0 /* In seconds */
let totalDelayTime = DispatchTime.now() + delayDuration
DispatchQueue.main.asyncAfter(deadline: totalDelayTime, execute: { view?.isPaused = true })
It will wait 1 second before evaluating the view?.isPaused