SKSpriteNode导致场景变灰

SKSpriteNode causes scene to be grayed out

我创建了一个 SKSpriteNode 并将其添加到我的 SKScene 中的场景图中:

// First I set a white background
self.backgroundColor = SKColor.whiteColor()
let cannon = SKSpriteNode(imageNamed: "cannon")
cannon.size = CGSizeMake(32, 160)
cannon.position = CGPointMake(size.width / 2.0, 0)
self.addChild(cannon)

这是"cannon.png",在我的Images.xcassets(我的不好,这是一门非常难看的大炮):

如果我添加它,我会得到一个完全灰色的场景,而如果我评论最后一行(所以我不会将精灵添加到场景中),我会得到一个白色背景。

您需要先初始化 scenesize,然后再向其中添加节点。像这样修改你的初始化方法,问题就解决了。

let scene = GameScene(size: view.bounds.size)