【发布时间】:2020-01-21 16:14:59
【问题描述】:
真的不知道如何解决这个问题。每当游戏启动时,它就会崩溃并给我这个输出。我查看了有关此问题的其他几篇文章,但它们没有帮助。
错误发生在“让敌人球”行我评论问题出现的地方
@objc func spawnEnem() {
let enemyBall = SKSpriteNode(imageNamed: "enemyBall") #Thread 1: breakpoint 1.1 issue HERE
self.addChild(enemyBall)
enemyBall.size = CGSize(width: 25.0, height: 25.0)
enemyBall.physicsBody = SKPhysicsBody(circleOfRadius: enemyBall.size.width/2)
enemyBall.physicsBody?.affectedByGravity = true
// Physics of our enemy
enemyBall.physicsBody = SKPhysicsBody(circleOfRadius: enemyBall.size.width / 2)
enemyBall.physicsBody?.categoryBitMask = PhysicsCatagroy.EnemyHere // setting enemyBall to our physics
enemyBall.physicsBody?.contactTestBitMask = PhysicsCatagroy.smallBall | PhysicsCatagroy.mainBall // if our enemy ball hits the small ball or main ball run this
enemyBall.physicsBody?.collisionBitMask = PhysicsCatagroy.smallBall | PhysicsCatagroy.mainBall // allows enemy Ball to collide with these small ball and main ball
enemyBall.physicsBody?.isDynamic = false // we dont want enemy effected by gravity
enemyBall.name = "Enemy"
switch randomPosNum {
case 0:
enemyBall.position.x = 0
let posY = arc4random_uniform(UInt32(frame.size.height))
enemyBall.position.y = CGFloat(posY)
break
case 1:
enemyBall.position.y = 0
let posX = arc4random_uniform(UInt32(frame.size.width))
enemyBall.position.x = CGFloat(posX)
break
case 2:
enemyBall.position.y = frame.size.height
let posX = arc4random_uniform(UInt32(frame.size.width))
enemyBall.position.x = CGFloat(posX)
break
case 3:
enemyBall.position.x = frame.size.width
let posY = arc4random_uniform(UInt32(frame.size.height))
enemyBall.position.y = CGFloat(posY)
break
default:
break
}
enemyBall.run(SKAction.move(to: mainBall.position, duration: 3)) // moves enemy ball to the player ball
}
【问题讨论】:
-
你有一个活动断点,删除它
标签: swift xcode sprite-kit