这是iOS 9。我无法设置SKView的背景色,它总是以默认的灰色呈现。有办法绕道吗?
let frame = CGRect(x: 0, y: 0, width: 200, height: 100)
let spriteView = SKView(frame: frame)
spriteView.backgroundColor = .blueColor()
self.view.addSubview(spriteView)当运行上述代码时,SKView是灰色的,而不是蓝色的。我真正想要做的是设置allowsTransparency = true,但如果不能将背景色更改为clearColor,则无法使其工作。
还有人碰到这个吗?有什么解决办法吗?
更新
即使有了@Danilo的建议,这仍然显示为灰色:
let frame = CGRect(x: 0, y: 0, width: 200, height: 100)
let spriteView = SKView(frame: frame)
spriteView.backgroundColor = .clearColor()
spriteView.allowsTransparency = true
spriteView.opaque = false更新
显然,设置backgroundColor的SKView没有效果,但是如果您将其设置为任何东西,那么allowsTransparency = true就无法工作。
发布于 2016-06-04 23:40:22
除了添加一个SKView之外,我们还需要一个由SKView表示的SKScene;然后调整/更改SKScene的backgroundColor。反过来,一个节点将被添加到场景中。
例如:
//create a SKView, which takes up the same frame as our view
let spriteView = SKView(frame: self.view.bounds)
//adding spriteView as a child view of our view
self.view.addSubview(spriteView)
//Here, we create a scene, which is the root object of
//the graph
let scene = SKScene(size: spriteView.frame.size)
scene.backgroundColor = .orangeColor()
//As said, we present the scene with our SKView
spriteView.presentScene(scene)
//Here, we create a node, which will be added by our scene
//This node takes up a size that you originally created and has the
//background color set to blue
let nodeFrame = CGRect(x: 0, y: 0, width: 200, height: 100)
let node = SKSpriteNode(color: .blueColor(), size: nodeFrame.size)
//The following just serves to show how we can adjust the node's
//position; I will leave that to you
node.position = CGPointMake(scene.frame.size.width - 200, scene.frame.size.height - 100)
//Finally, we add the node to our scene
scene.addChild(node)发布于 2016-06-04 23:53:21
let spriteView = SKView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
let spriteKitScene = SKScene(size: spriteView.frame.size)
spriteKitScene.backgroundColor = SKColor.blackColor()
spriteView.presentScene(spriteKitScene)
self.view.addSubview(spriteView)https://stackoverflow.com/questions/37635528
复制相似问题