我正在尝试制作一个在游戏启动时显示的标签,但它一启动就崩溃了。错误是“由于未捕获的异常‘NSInvalidArgumentException’而终止应用程序,原因:‘尝试添加已经有父级的 SKNode:名称:‘(null)’文本:‘点击任何地方即可开始!’ fontName:'Copperplate' 位置:{187.5, 333.5}'"。这是我的代码:
let startGameTextNode = SKLabelNode(fontNamed: "Copperplate")
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override init(size: CGSize) {
super.init(size: size)
startGameTextNode.text = "TAP ANYWHERE TO START!"
startGameTextNode.horizontalAlignmentMode = SKLabelHorizontalAlignmentMode.Center
startGameTextNode.verticalAlignmentMode = SKLabelVerticalAlignmentMode.Center
startGameTextNode.fontSize = 20
startGameTextNode.fontColor = SKColor.whiteColor()
startGameTextNode.position = CGPoint(x: scene!.size.width / 2, y: scene!.size.height / 2)
addChild(startGameTextNode)
我的背景纹理确实在游戏启动后也会移动,但我不确定这是否会导致问题。
最佳答案
没关系。我成功了。我在现场添加它太晚了。我只是在将地面添加到场景之前将其向上移动,然后应用程序开始工作。
关于ios - 由于未捕获的异常而终止应用程序(尝试添加已具有父级的 SKNode)错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31487207/