每当我产生一个新实体时,我的游戏都会冻结

时间:2017-01-16 09:21:00

标签: swift xcode sprite-kit

我的精灵套件xcode游戏有问题。每当我产生一个新的"硬币"我的游戏冻结了几秒钟。谁知道为什么会这样?这是我目前的代码:

   func createAttest() {
    let AttestTexture = SKTexture(imageNamed: "Attest")

    let Attest = SKSpriteNode(texture: AttestTexture)
    Attest.physicsBody = SKPhysicsBody(texture: AttestTexture, size: AttestTexture.size())
    Attest.physicsBody?.isDynamic = false
    Attest.name = "Attest"

    addChild(Attest)

    //random
    let xPosition = frame.width + Attest.frame.width

    let max = Int(frame.height / 4)
    let random = GKRandomDistribution(lowestValue: 300, highestValue: max)
    let yPosition = CGFloat(random.nextInt())

    Attest.position = CGPoint(x: xPosition, y: yPosition + Attest.size.height)

    let endPosition = frame.width + (Attest.frame.width * 2)

    let moveAction = SKAction.moveBy(x: -endPosition, y: 0, duration: 4.2)
    let moveSequence = SKAction.sequence([moveAction, SKAction.removeFromParent()])
    Attest.run(moveSequence)




}

//spawntimes
func startAttest() {
    let make = SKAction.run {[unowned self] in

        self.createAttest()
    }
    let time = SKAction.wait(forDuration: 15)
    let sequence = SKAction.sequence([make, time])
    let infinity = SKAction.repeatForever(sequence)

    run(infinity)
}

所有见解将不胜感激。 :)

0 个答案:

没有答案