我创建了渐变背景,现在我以前拥有的所有按钮都不可见。但是按钮仍然存在,因为如果我触摸例如播放按钮所在的区域,控制台将打印:“按下播放按钮”。如何使按钮再次可见?
代码:
import UIKit
import SpriteKit
import StoreKit
import GameKit
import AVFoundation
import SpriteKit.SKTexture
class Start: SKScene {
//Button
let settingButton = SKSpriteNode(imageNamed: "Settings")
let playButton = SKSpriteNode(imageNamed: "NewGame")
//Background
func makeGradientColor(`for` object : AnyObject , startPoint : CGPoint , endPoint : CGPoint) -> CAGradientLayer {
let gradient: CAGradientLayer = CAGradientLayer()
gradient.colors = [(UIColor(red: 12/255.0, green: 121/255.0, blue: 208/255.0, alpha: 1.00).cgColor), (UIColor(red: 85/255.0, green: 229/255.0, blue: 254/255.0, alpha: 1.00).cgColor)]
gradient.locations = [0.0 , 1.0]
gradient.startPoint = startPoint
gradient.endPoint = endPoint
gradient.frame = CGRect(x: 0.0, y: 0.0, width: object.frame.size.width, height: object.frame.size.height)
return gradient
}
override func didMove(to view: SKView) {
//Background
let start1 : CGPoint = CGPoint(x: 1.0, y: 1.0)
let end1 : CGPoint = CGPoint(x: 1.0, y: 0.0)
let gradient1: CAGradientLayer = self.makeGradientColor(for: (self.view ?? nil)!, startPoint: start1, endPoint: end1)
self.view?.layer.insertSublayer(gradient1, at: 0)
//Button
playButton.setScale(0.6)
playButton.zPosition = 1
playButton.position = CGPoint(x: self.size.width / 2, y: self.size.height * 0.4)
self.addChild(playButton)
settingButton.setScale(0.4)
settingButton.zPosition = 1
settingButton.position = CGPoint(x: self.size.width * 0.9, y: self.size.height * 0.94)
self.addChild(settingButton)
}
}