在spriteKit下运行的应用程序。几天前,gameScene在加载gameViewController后加载。今天,我改变了加载动作,只有在单击“开始”按钮时才加载gameScene,这意味着gameScene背景颜色是不可见的,我需要为gameViewController设置背景颜色。这是一项非常简单的任务,已经完成了很多次 之前,但它坚持浅灰色(下图)。
不能在spriteKit下更改gameViewController背景颜色吗?
我必须改变gameScene背景颜色吗?
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = .green
// .......
}
@IBAciton func loadGameView() {
if let view = self.view as! SKView? {
// Load the SKScene from 'GameScene.sks'
// if let scene = SKScene(fileNamed: "GameScene") {
if let scene = GameScene(fileNamed: "GameScene") {
scene.viewController = self
scene.size = self.view.frame.size
scene.scaleMode = .aspectFill
// Present the scene
view.presentScene(scene)
}
view.ignoresSiblingOrder = false
view.showsFPS = false
view.showsNodeCount = false
view.showsDrawCount = false
}
}
答案 0 :(得分:1)
if let scene = GameScene(fileNamed: "GameScene") {
scene.viewController = self
scene.size = self.view.frame.size
scene.scaleMode = .aspectFill
//ADD THIS
scene.color = .green
scene.colorBlendFactor = 1
// Present the scene
view.presentScene(scene)
}