尝试添加已经具有父级和线程1的SKNode:signal SIGABRT

时间:2019-04-13 23:36:07

标签: ios swift sprite-kit sigabrt

我尝试使用类小行星,但我不断收到此错误消息。我尝试了一切,但似乎无法弄清楚。

只有一个小行星出现,然后在

上出现一条线
  

AppDelegate:线程1:信号SIGABRT

我是个快速入门的人,欢迎您的帮助。

class Asteroides:SKSpriteNode {

    init(img:String){
        let texture = SKTexture(imageNamed: img)
        super.init(texture: texture, color: .clear, size: texture.size())
        self.name = "Asteroid"
        self.setScale(0.2)
        self.zPosition = 2

        self.physicsBody = SKPhysicsBody(circleOfRadius: self.size.width/3.3, center: self.anchorPoint)
        self.physicsBody!.affectedByGravity = false
        self.physicsBody!.categoryBitMask = GameScene.physicsCategories.asteroid
        self.physicsBody!.collisionBitMask = GameScene.physicsCategories.none
        self.physicsBody!.contactTestBitMask  = GameScene.physicsCategories.planet | GameScene.physicsCategories.bullet
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    func random() -> CGFloat {
        return CGFloat(Float(arc4random()) / 0xFFFFFFFF) //générer un nombre aléatoire
    }


    func random(min: CGFloat, max: CGFloat) -> CGFloat {
        return random() * (max - min) + min
    }


    func addAsteroid (parent: GameScene)  {

        let randomStart1 = random(min: self.size.height/2, max: parent.size.height - self.size.height/2)
        let startPoint1 =  CGPoint(x:randomStart1 , y:parent.size.width + self.size.width/2 )
        let endPoint1   =  CGPoint(x: randomStart1, y: -self.size.width/2)

        self.position = startPoint1
        parent.addChild(self)

        let moveAsteroid = SKAction.move(to: endPoint1 , duration: 3.5)
        let deleteAsteroide = SKAction.removeFromParent()
        let asteroidSeq = SKAction.sequence([moveAsteroid,deleteAsteroide])

        self.run(SKAction.repeatForever(asteroidSeq))
    }
 }

在GameScene中:

 private var asteroide = Asteroides(img: "Asteroid")

    func newlevel(){
        func parametersLevel(spawn : SKAction){
            let spawning = spawn
            let waitSpawn = SKAction.wait(forDuration: 0.8)
            let sequence = SKAction.sequence([waitSpawn,spawning])//sequence:asteroides+attendre 0.8 sec
            let spawnForever = SKAction.repeatForever(sequence)
            self.run(spawnForever)
        }
        parametersLevel(spawn:SKAction.run(asteroids))
    }

    func asteroids (){
        asteroide.addAsteroid(parent: self)
     }

0 个答案:

没有答案