Adding the pause functionality
To pause a game during gameplay is an important functionality. Our game will benefit from the pause
functionality; it will allow the player to continue from where they left off previously.
Let's add the pause
functionality:
Primarily, we'll create a Play/Pause button for
GameScene
and configure the position and image for the button. We will add the following lines of code inside theGameScene.swift
class:var pauseBtn:SKSpriteNode = SKSpriteNode(imageNamed: "PLAY-PAUSE")
Set the attributes of the
pauseBtn
label, such assize
,position
, and so on, as we did earlier for the other labels in theaddPlayPauseButton()
method. This is how it will look:func addPlayPauseButton() { //self.runAction(sound) self.pauseBtn.name = "PAUSE" self.pauseBtn.zPosition = 3 self.pauseBtn.position = CGPointMake(CGRectGetMaxX(self.frame) - pauseBtn.frame.width/2 , CGRectGetMaxY(self.frame) - pauseBtn.frame.height/2) self.addChild(pauseBtn) }
Please...