gpt4 book ai didi

ios - SpriteKit 暂停恢复错误

转载 作者:搜寻专家 更新时间:2023-11-01 07:11:11 26 4
gpt4 key购买 nike

override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch = touches.first
let touchLocation = touch!.location(in: self)
if continueButton.contains(touchLocation) {
scene?.view?.isPaused = false
pauseMenu.removeFromParent()
self.addChild(pauseButton)
self.addChild(upButton)
continueButton.removeFromParent()
}
}

当触摸在继续按钮上结束时,我遇到线程 1:Signal SIGABRT 错误。我发现的是,如果我在 touches 结束时声明 Sprite (继续按钮),按钮不会被删除,但是,当我在函数外部声明继续按钮 Sprite 时,继续按钮被删除。问题是有时应用程序只会崩溃显示线程 1 错误。关于如何阻止崩溃的任何想法?

class GameScene: SKScene {
var mainturret = SKSpriteNode(imageNamed: "Main Turret")
var pauseButton = SKSpriteNode(imageNamed: "Pause Simbol")
var angleToShoot = 0
var touchIsOn = 0
var pointTwoSecondInterval = 0
let pauseMenu = SKSpriteNode(imageNamed: "Paused")
var zombieSpawningTimer = Timer()
var upButton = SKSpriteNode(imageNamed: "Up Button")
let downButton = SKSpriteNode(imageNamed: "Down Button")
let popUpMenu = SKSpriteNode(imageNamed: "TurretSpot")
var continueButton = SKSpriteNode(imageNamed: "Continue")
...}

这是声明按钮的地方(在函数之外)

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

错误发生在第三行代码。这是电脑告诉我的。

2017-06-30 07:32:26.053429-0600 Survive the Night[4635:1030550] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attemped to add a SKNode which already has a parent: name:'(null)' texture:[ 'Up Button' (200 x 200)] position:{0, -254} scale:{0.57, 0.57} size:{56.800003051757812, 56.800003051757812} anchor:{0.5, 0.5} rotation:0.00' * First throw call stack: (0x188da6fd8 0x187808538 0x188da6f20 0x1984f1738 0x1984f1664 0x100073d40 0x100074908 0x1984d7050 0x18ef0a46c 0x18ef05804 0x18eed6418 0x18f6cff64 0x18f6ca6c0 0x18f6caaec 0x188d55424 0x188d54d94 0x188d529a0 0x188c82d94 0x18a6ec074 0x18ef3b130 0x100078c5c 0x187c9159c) libc++abi.dylib: terminating with uncaught exception of type NSException

最佳答案

原因是因为您将 upButton 作为某个节点的子节点添加了两次。

很可能是 touchesEnded 方法中的 self.addChild(upButton) 行导致了问题。此时,验证 upButton.parent 是否为 nil。如果不是,则您的代码中存在逻辑错误。

关于ios - SpriteKit 暂停恢复错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44838484/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com