填充发电机。可能吗?

时间:2015-11-24 16:56:03

标签: swift sprite-kit skshapenode

我有一个生成器,它每隔2秒从y轴生成一个圆圈(SKShapeNode)。 (向上移动)。我想知道是否可以统一填充这个生成器(每x个点。

以下是我的代码:

class CircleGen: SKShapeNode {
    var circles = [WhiteCircles]()
    var circleTracker = [WhiteCircles]()
    var generationTimer: NSTimer!
    var circ: WhiteCircles!

    func generateCircles() {
        for var i = 0; i < 4; i++ {
            var scale: CGFloat
            let rand = arc4random_uniform(10)
            if rand == 0 {
                scale = -15.0
            } else {
                scale = 15.0
            }
            let circle = WhiteCircles()
            circle.position.x = lineGen.position.x

            circle.physicsBody?.affectedByGravity = false
            circle.position.y = 35
            self.circles.append(circle)
            circleTracker.append(circle)
            foregroundNode.addChild(circle)
        }
    }

    func startGeneratingEvery(seconds: NSTimeInterval) {
        let callGenerateAction = SKAction.runBlock { () -> Void in
            self.generateCircles()
        }
        let waitOneSecond = SKAction.waitForDuration(seconds)

        let sequenceAction = SKAction.sequence([callGenerateAction, waitOneSecond])

        let circleGenerateAction = SKAction.repeatActionForever(sequenceAction)
        self.runAction(circleGenerateAction, withKey: "generateCircles")
    }
}

如有必要,会发布更多代码。先感谢您。

0 个答案:

没有答案