[英]How do I change background colour programmatically in swift using SpriteKit
I have this game and I have a function for when each different game mode is called, I want to change the colour of the background when a mode is clicked, but when I do It nothing happens. 我有这个游戏,并且有一个用于调用每个不同游戏模式的功能,当我单击某个模式时,我想更改背景的颜色,但是当我这样做时,它什么也没发生。 Could you please tell me how to do it, Thanks
你能告诉我怎么做吗,谢谢
override func update(_ currentTime: TimeInterval) {
// Called before each frame is rendered
switch currentGameType {
case .easy:
enemy.run(SKAction.moveTo(x: ball.position.x, duration: 1.3))
break
case .medium:
enemy.run(SKAction.moveTo(x: ball.position.x, duration: 1.0))
self.view?.backgroundColor = UIColor.white //I TRY IT HERE
break
case .hard:
enemy.run(SKAction.moveTo(x: ball.position.x, duration: 0.7))
break
case .player2:
break
}
Your scene's background has nothing to do with the view's background. 场景的背景与视图的背景无关。
You should set the scene's background color instead. 您应该改为设置场景的背景色。 The scene, in this case, is
self
: 在这种情况下,场景是
self
:
self.backgroundColor = .white
However, if you want to use an image for the background, you need to add a new node covering the whole scene and set the texture of the node to be your image. 但是,如果要将图像用作背景,则需要添加一个覆盖整个场景的新节点,并将该节点的纹理设置为图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.