この質問は、私がSpriteKitで行っているGalagaのゲームについて先に質問した質問に関連しています。 (Cannot assign value of type '[SKNode]' to type 'SKSpriteNode!')私は新しい質問でそこに行っていた会話を続けています。スレッド1:SpriteKitゲームでSIGABRTエラーが発生しました
私はスレッド1のシグナルを持っています:私のゲームで火事のボタンを押すと、App DelegateのSIGABRTエラーが発生します(火花ボタンはSKSpriteNodeです)。時には火が鳴りますが、ポジション。それ以外の場合は、SIGABRTエラーが発生します。それはおそらく
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
let location = (touch as UITouch).location(in: self)
let nodes = self.nodes(at: location)
for node in nodes {
if node.name == "FireButton" {
shoot()
} else {
let touchLocation = touch.location(in: self)
spaceship.position.x = touchLocation.x
}
}
}
}
fireLaser
機能、
func fireLaser(laser: SKNode, toDestination destination: CGPoint, withDuration duration: CFTimeInterval, andSoundFileName soundName: String) {
let laserAction = SKAction.sequence([
SKAction.move(to: destination, duration: duration),
SKAction.wait(forDuration: 3.0/60.0),
SKAction.removeFromParent()
])
addChild(laser)
laser.run(SKAction.group([laserAction]))
}
またはshoot
機能、私のtouchesBegan
機能のコードから来ています。
func shoot() {
self.laser.position = CGPoint(x: self.spaceship.position.x, y:
self.spaceship.position.y + self.spaceship.frame.height -
self.laser.frame.height/2)
self.addChild(self.laser)
let laserDestination = CGPoint(x: self.spaceship.position.x, y:
self.frame.height + self.laser.frame.height/2)
self.fireLaser(laser: self.laser, toDestination: laserDestination, withDuration: 1.0, andSoundFileName: "laser sound effect.mp3")
}
エラーが発生したときに表示される画面のスクリーンショットです。 ( 0 CoreFoundationのを0x0000000105cfcb0b: [エラーのスクリーンショット] [1]
はまた、ここで私はエラーを取得する際に、コンソールに出力したメッセージは
2017-06-12 17:02:06.100 Galaga Copy[790:23281] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attemped to add a SKNode which already has a parent: <SKSpriteNode> name:'(null)' texture:[<SKTexture> 'Laser' (27 x 150)] position:{-5.8244380950927734, -411.53384399414062} scale:{1.00, 1.00} size:{13.5, 75} anchor:{0.5, 0.5} rotation:0.00'
は***まずスローコールスタック、ですexceptionPreprocess + 171 1 libobjc.A.dylib 0x000000010261f141 objc_exception_throw + 48 2 CoreFoundationの0x0000000105d65625 + [NSExceptionレイズ:フォーマット:] + 197 3 SpriteKitベース0x0000000103218c95 - [SKNode insertChild:atIndex:] + 162 4 SpriteKitベース0x0000000103218bd2 - [SKNodeはaddChild:] + 68 5ギャラガコピー0x0000000102036601 _TFC11Galaga_Copy9GameScene5shootfT_T_ 7ギャラガコピー0x0000000102037436 _TToFC11Galaga_Copy9GameScene12touchesBeganfTGVs3SetCSo7UITouch_4withGSqCSo7UIEvent__T_ + 102 8 SpriteKitベースの0x00000001032007c4 _TFC11Galaga_Copy9GameScene12touchesBeganfTGVs3SetCSo7UITouch_4withGSqCSo7UIEvent__T_ + 1431 + 1089 6ギャラガコピー0x0000000102036f57 - [SKView touchesBegan:withEvent:] + 1130 9のUIKit 0x000000010347154b - [UIWindow _sendTouchesForEvent:] + 2036 10のUIKit 0x0000000103472f00 - [UIWindowのSendEvent:] + 4114 11のUIKit 0x000000010341fa84 - [のUIApplicationのSendEvent:] + 352 12のUIKitは0x00 00000103c035d4 __dispatchPreprocessedEventFromEventQueue + 2926 13のUIKit 0x0000000103bfb532 __handleEventQueue + 1122 14 CoreFoundationの0x0000000105ca2c01 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 15 CoreFoundationの0x0000000105c880cf __CFRunLoopDoSources0 + 527 16 CoreFoundationの0x0000000105c875ff __CFRunLoopRun + 911 17 CoreFoundationの0x0000000105c87016 CFRunLoopRunSpecific + 406 18 GraphicsServices 0x000000010a159a24 GSEventRunModal + 62 19のUIKit 0x0000000103402134 UIApplicationMain + 159 20 Galagaコピー0x0000000102039b07メイン+ 55 21 libdyld.dylib 0x0000000106c9c65d start + 1 ) libC++ abi。dylib:NSException タイプのキャッチされない例外で終了する(lldb)それはすべての調子が悪いのですが、私はそれが正しく表示させる方法を見つけ出すことができないことを
申し訳ありません。誰もがこれで私を助けてくれる?
画面の右下に印刷されているものの詳細を追加することもできますか。 – JohnV
同じノード「レーザー」を複数回追加しています。毎回新しいレーザーのインスタンスを作成する必要があります。 –
私が持っている別のアイデア。ユーザーは火のボタンを押さなくても船をただ発射させる方法を誰もが知っていますか?それは私が多くの事を複雑にしているボタンを持つ必要はないので、より簡単に行うことができます。 – Shock9616