我使用一個遊戲程序模板斯威夫特3後,當我從我的轉變從「開始」屏幕「開始」屏幕上我的「遊戲」的場景,按鈕不會消失。 我讀過其他人的帖子,但沒有任何幫助。我的按鈕是一個編程添加的UIButton有uibezierpath圓角矩形按鈕背後使它看起來不錯。問題是,它(按鈕,UIBezierpath)不會消失,當我改變場景 - 它在完全相同的斑點爲「開始」屏幕。 我的按鈕代碼與UIBezierpath:編程方式添加的UIButton不會消失切換場景
let playAgain = UIButton()
playAgain.frame = CGRect(x: 225, y: 247, width: 115, height: 36)
playAgain.backgroundColor = SKColor.lightGray
playAgain.setTitle("Play", for: .normal)
playAgain.setTitleColor(.black, for: .normal)
self.view?.addSubview(playAgain)
playAgain.addTarget(self, action: #selector(playAgainTapped(_:)), for: .touchUpInside)
//now for the bezierpath/ rounded rect
//let doYourPath = UIBezierPath(rect: CGRect(x: 20, y: 20, width: 100, height: 36))
//this also works
let roundRect = UIBezierPath(roundedRect: CGRect(x: 218, y: 240, width: 130, height: 50), cornerRadius: 18)
let layer = CAShapeLayer()
layer.path = roundRect.cgPath
layer.strokeColor = UIColor.black.cgColor
layer.fillColor = UIColor.lightGray.cgColor
self.view?.layer.addSublayer(layer)
func playAgainTapped(_ sender: Any?) -> Void {
print("***********")
backToGame()
}
切換場景代碼:
func backToGame(){
removeAllChildren()
run(SKAction.sequence([
SKAction.wait(forDuration: 3.0),
SKAction.run() {
// 5
let reveal = SKTransition.flipHorizontal(withDuration: 0.5)
let scene = GameScene(size: self.size)
self.view?.presentScene(scene, transition:reveal)
}
]))
}
任何想法?
'removeAllChildren'做了什麼? – the4kman
@ the4kman它會從按鈕上的文本。 –