线程1:断点1.1 Xcode Swift

lkaoscv7  于 2023-06-30  发布在  Swift
关注(0)|答案(2)|浏览(135)

真的不知道如何解决这个问题。每当游戏启动它崩溃,并给我这个输出。我看了一些关于这个问题的其他文章,但它们没有帮助。
错误发生在'让敌人球'行我评论的地方出现的问题

@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


    }
slmsl1lt

slmsl1lt1#

您有一个活动的断点:

Press CMD + 8

要查看活动断点,请单击左侧显示的任何内容,然后单击删除按钮,它应该看起来像这样:

然后再试一次。
断点是一种调试代码的方法,它基本上是一种在特定点停止代码的东西,以查看执行了什么,以什么顺序执行,以及哪些变量分配了什么数据。

tzxcd3kk

tzxcd3kk2#

谢谢你帮了我,而且很有效; D

相关问题