![](/img/trans.png)
[英]Terminating app due to uncaught exception 'NSInternalInconsistencyException' error
[英]Terminating app due to uncaught exception due to uncaught exception (Attemped to add a SKNode which already has a parent) error
我正在嘗試制作一個標簽,該標簽將在游戲啟動時顯示,但是一旦啟動它就會崩潰。 錯誤是“由於未捕獲的異常'NSInvalidArgumentException'而終止應用程序,原因:'試圖添加已經具有父級的SKNode:名稱:'(null)'文本:'TAP ANYWHERE TO STARTER!' 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)
我確實有一個背景紋理,它在游戲啟動時也會移動,並且我不確定這是否是導致問題的原因。
沒關系。 我知道了 我在場景中添加得太晚了。 在將場景添加到地面上之前,我只是將其向上移動,然后該應用開始工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.