话题一:Signal SIGABRT sprite kit
Posted
技术标签:
【中文标题】话题一:Signal SIGABRT sprite kit【英文标题】:Thread 1: Signal SIGABRT sprite kit 【发布时间】:2016-06-25 09:13:14 【问题描述】:我试图在 x 方向上生成多个节点,然后在 y 方向上将它们作为一个单元生成。我在 x 方向生成节点。我创建了一个包含沿 x 方向移动的节点的父节点,并尝试在 y 方向移动父节点。我在 AppDelegate 中不断收到“线程 1:信号 SIGABRT”。这是正确的方法吗?
这是我目前所拥有的:
func addCloud()
var i = arc4random_uniform(2)
// RandomCloud
Cloud = SKSpriteNode(imageNamed: "Cloud\(i)")
// Position
Cloud.size = CGSize(width: self.size.width/3.5, height: self.size.height/12)
Cloud.position = CGPointMake(self.frame.size.width*0.1 , self.frame.size.height*0.65)
var radius = CGFloat(Cloud.size.width/2)
Cloud.physicsBody = SKPhysicsBody(circleOfRadius: radius)
Cloud.physicsBody?.categoryBitMask = PhysicsCategory.Cloud
Cloud.physicsBody?.collisionBitMask = PhysicsCategory.character
Cloud.physicsBody?.contactTestBitMask = PhysicsCategory.character
Cloud.physicsBody?.dynamic = false
Cloud.physicsBody?.affectedByGravity = false
Cloud.zPosition = 4
allCloud.addChild(Cloud)
Cloud.runAction(move)
func add1()
var i = arc4random_uniform(2)
Cloud1 = SKSpriteNode(imageNamed: "Cloud\(i)")
Cloud1.position = CGPointMake(self.frame.size.width*0.5 , self.frame.size.height*0.65)
Cloud1.size = CGSize(width: self.size.width/3.5, height: self.size.height/12)
Cloud1.zPosition = 4
var radius = CGFloat(Cloud1.size.width/2)
Cloud1.physicsBody = SKPhysicsBody(circleOfRadius: radius)
Cloud1.physicsBody?.categoryBitMask = PhysicsCategory.Cloud
Cloud1.physicsBody?.collisionBitMask = PhysicsCategory.character
Cloud1.physicsBody?.contactTestBitMask = PhysicsCategory.character
Cloud1.physicsBody?.dynamic = false
Cloud1.physicsBody?.affectedByGravity = false
allCloud.addChild(Cloud1)
Cloud1.runAction(move1)
func add2()
var i = arc4random_uniform(2)
Cloud2 = SKSpriteNode(imageNamed: "Cloud\(i)")
Cloud2.position = CGPointMake(self.frame.size.width*0.9 , self.frame.size.height*0.65)
Cloud2.size = CGSize(width: self.size.width/3.5, height: self.size.height/12)
Cloud2.zPosition = 4
var radius = CGFloat(Cloud2.size.width/2)
Cloud2.physicsBody = SKPhysicsBody(circleOfRadius: radius)
Cloud2.physicsBody?.categoryBitMask = PhysicsCategory.Cloud
Cloud2.physicsBody?.collisionBitMask = PhysicsCategory.character
Cloud2.physicsBody?.contactTestBitMask = PhysicsCategory.character
Cloud2.physicsBody?.dynamic = false
Cloud2.physicsBody?.affectedByGravity = false
allCloud.addChild(Cloud2)
Cloud2.runAction(move2)
func add3()
var i = arc4random_uniform(2)
Cloud3 = SKSpriteNode(imageNamed: "Cloud\(i)")
Cloud3.position = CGPointMake(self.frame.size.width + Cloud3.size.width/2 , self.frame.size.height*0.65)
Cloud3.size = CGSize(width: self.size.width/3.5, height: self.size.height/12)
Cloud3.zPosition = 4
var radius = CGFloat(Cloud3.size.width/2)
Cloud3.physicsBody = SKPhysicsBody(circleOfRadius: radius)
Cloud3.physicsBody?.categoryBitMask = PhysicsCategory.Cloud
Cloud3.physicsBody?.collisionBitMask = PhysicsCategory.character
Cloud3.physicsBody?.contactTestBitMask = PhysicsCategory.character
Cloud3.physicsBody?.dynamic = false
Cloud3.physicsBody?.affectedByGravity = false
allCloud.addChild(Cloud3)
Cloud3.runAction(move3)
func add4()
var i = arc4random_uniform(2)
Cloud4 = SKSpriteNode(imageNamed: "Cloud\(i)")
Cloud4.position = CGPointMake(self.frame.size.width + Cloud4.size.width/2 , self.frame.size.height*0.65)
Cloud4.size = CGSize(width: self.size.width/3.5, height: self.size.height/12)
Cloud4.zPosition = 4
var radius = CGFloat(Cloud4.size.width/2)
Cloud4.physicsBody = SKPhysicsBody(circleOfRadius: radius)
Cloud4.physicsBody?.categoryBitMask = PhysicsCategory.Cloud
Cloud4.physicsBody?.collisionBitMask = PhysicsCategory.character
Cloud4.physicsBody?.contactTestBitMask = PhysicsCategory.character
Cloud4.physicsBody?.dynamic = false
Cloud4.physicsBody?.affectedByGravity = false
allCloud.addChild(Cloud4)
Cloud4.runAction(move4)
func add5()
var i = arc4random_uniform(2)
Cloud5 = SKSpriteNode(imageNamed: "Cloud\(i)")
Cloud5.position = CGPointMake(self.frame.size.width + Cloud5.size.width/2 , self.frame.size.height*0.65)
Cloud5.size = CGSize(width: self.size.width/3.5, height: self.size.height/12)
Cloud5.zPosition = 4
var radius = CGFloat(Cloud5.size.width/2)
Cloud5.physicsBody = SKPhysicsBody(circleOfRadius: radius)
Cloud5.physicsBody?.categoryBitMask = PhysicsCategory.Cloud
Cloud5.physicsBody?.collisionBitMask = PhysicsCategory.character
Cloud5.physicsBody?.contactTestBitMask = PhysicsCategory.character
Cloud5.physicsBody?.dynamic = false
Cloud5.physicsBody?.affectedByGravity = false
allCloud.addChild(Cloud5)
Cloud5.runAction(move5)
func add6()
var i = arc4random_uniform(2)
Cloud6 = SKSpriteNode(imageNamed: "Cloud\(i)")
Cloud6.position = CGPointMake(self.frame.size.width + Cloud6.size.width/2 , self.frame.size.height*0.65)
Cloud6.size = CGSize(width: self.size.width/3.5, height: self.size.height/12)
Cloud6.zPosition = 4
var radius = CGFloat(Cloud6.size.width/2)
Cloud6.physicsBody = SKPhysicsBody(circleOfRadius: radius)
Cloud6.physicsBody?.categoryBitMask = PhysicsCategory.Cloud
Cloud6.physicsBody?.collisionBitMask = PhysicsCategory.character
Cloud6.physicsBody?.contactTestBitMask = PhysicsCategory.character
Cloud6.physicsBody?.dynamic = false
Cloud6.physicsBody?.affectedByGravity = false
Cloud6.runAction(move6)
allCloud.addChild(Cloud6)
func addall ()
self.addChild(allCloud)
allCloud.runAction(move7)
func spawnCloudX()
var remove = SKAction.runBlock(self.allCloud.removeFromParent())
var distance = CGFloat(self.frame.size.width + Cloud.size.width/2)
var distance1 = CGFloat(self.frame.size.width + Cloud1.size.width/2)
var distance2 = CGFloat(self.frame.size.width + Cloud2.size.width/2)
var distance3 = CGFloat(self.frame.size.width + Cloud3.size.width/2)
var distance4 = CGFloat(self.frame.size.width + Cloud4.size.width/2)
var distance5 = CGFloat(self.frame.size.width + Cloud5.size.width/2)
var distance6 = CGFloat(self.frame.size.width + Cloud6.size.width/2)
var add:SKAction = SKAction.runBlock(
() in
self.addCloud())
var add1:SKAction = SKAction.runBlock(
() in
self.add1())
var add2:SKAction = SKAction.runBlock(
() in
self.add2())
var add3:SKAction = SKAction.runBlock(
() in
self.add3())
var add4:SKAction = SKAction.runBlock(
() in
self.add4())
var add5:SKAction = SKAction.runBlock(
() in
self.add5())
var add6:SKAction = SKAction.runBlock(
() in
self.add6)
var removea = SKAction.removeFromParent()
var movex = SKAction.moveToX(-distance, duration: 5)
var movex1 = SKAction.moveToX(-distance1, duration: 6.5)
var movex2 = SKAction.moveToX(-distance2, duration: 8)
var movex3 = SKAction.moveToX(-distance3, duration: 10)
var movex4 = SKAction.moveToX(-distance4, duration: 10)
var movex5 = SKAction.moveToX(-distance5, duration: 10)
var movex6 = SKAction.moveToX(-distance6, duration: 10)
var delay = SKAction.waitForDuration(2)
var spawn = SKAction.sequence([add3,delay,add4,delay,add5,delay,add6])
self.runAction(add)
self.runAction(add1)
self.runAction(add2)
var spawnforever = SKAction.repeatActionForever(spawn)
self.runAction(spawnforever)
move = SKAction.sequence([movex,removea])
move1 = SKAction.sequence([movex1,removea])
move2 = SKAction.sequence([movex2,removea])
move3 = SKAction.sequence([movex3,removea])
move4 = SKAction.sequence([movex4,removea])
move5 = SKAction.sequence([movex5,removea])
move6 = SKAction.sequence([movex6,removea])
var distance7 = CGFloat(self.frame.size.height + allCloud.size.height/2)
var movey7 = SKAction.moveToY(distance7, duration: 5)
var addall: SKAction = SKAction.runBlock(
() in
self.addall() )
var delayY = SKAction.waitForDuration(1)
var spawnY = SKAction.sequence([addall,delayY])
var spawnYforever = SKAction.repeatAction(spawnY, count: 2)
move7 = SKAction.sequence([movey7,removea])
self.runAction(spawnYforever)
抱歉,代码太长了。 谢谢,
【问题讨论】:
我已经查看了你的代码一个小时,但仍然无法弄清楚这样做的目的到底是什么。我已将您的代码从 200 多行清理为 70 行,但仍有太多冗余。请用简单的英语解释你想在屏幕上发生什么 很抱歉给您带来不便。我的目标是创建以特定速率在 x 轴上移动的单独节点。然后以一定的速率将 y 轴上的这些节点一起移动。因此分别在 x 轴和 y 轴作为一个单元生成。我希望它看起来像云向左移动和向上移动。我希望这是有道理的。谢谢。 这段代码对于你想要实现的目标来说太复杂了,它是巨大的矫枉过正。 云必须是物理体吗? 如果你想让它们向上移动,为什么要在 x 移动后移除云? 【参考方案1】:试试这个代码,看看它是否适合你。
spawnClouds()
func createCloud() -> SKSpriteNode
let i = arc4random_uniform(2) + 1
let randomPos = arc4random_uniform(200)
let cloud = SKSpriteNode(imageNamed: "cloud\(i)")
cloud.position = CGPointMake(self.size.width + cloud.size.width / 2 - CGFloat(50 + randomPos) , self.size.height * 0.65 - CGFloat(50 + randomPos))
cloud.zPosition = 4000
let radius = CGFloat(cloud.size.width / 2)
cloud.physicsBody = SKPhysicsBody(circleOfRadius: radius)
cloud.physicsBody?.categoryBitMask = PhysicsCategory.Cloud
cloud.physicsBody?.collisionBitMask = PhysicsCategory.Hero
cloud.physicsBody?.contactTestBitMask = PhysicsCategory.Hero
cloud.physicsBody?.dynamic = false
cloud.physicsBody?.affectedByGravity = false
addChild(cloud)
return cloud
func spawnClouds()
for _ in 0..<5
let addAndMoveCloud = SKAction.runBlock(
let randomDuration = CGFloat(arc4random_uniform(2)) / 5 + 10
let cloud = self.createCloud()
cloud.runAction(SKAction.moveTo(CGPoint(x: -cloud.size.width, y: self.size.height + cloud.size.height), duration: NSTimeInterval(randomDuration)), completion: cloud.removeFromParent()
)
)
let delay = SKAction.waitForDuration(2)
let spawnClouds = SKAction.sequence([addAndMoveCloud, delay])
runAction(SKAction.repeatActionForever(spawnClouds))
【讨论】:
这里的问题是云单独向上移动。这就是为什么我创建了一个父节点,以便子节点可以一起移动。 顺便说一句,当我调用一次重复操作(计数 = 1)时,我的代码可以完美运行。 200 多行代码来“完美”地在屏幕上移动一些云是主观的。我已经更改了代码以制作一组云 云层以一定角度移动。记住跑步机皮带的类比,它看起来不像那样。 嘿!我有一个新问题,你能帮帮我吗?以上是关于话题一:Signal SIGABRT sprite kit的主要内容,如果未能解决你的问题,请参考以下文章
iOS报错 thread 1: signal SIGABRT
线程1:自定义框架Swift中Reachability框架中的signal SIGABRT
c语言 不能加循环;Program received signal SIGABRT, Aborted. 0x0000003346a30265 in raise () from /l