0

Is there a way to spawn an SKSpriteNode continuously down the middle of the screen. For example I have a circle that I want to spawn in the middle of the x axis and then for that node to spawn all the way down the screen?

These circles are different colours so when they spawn is there a way to randomly change the the colour of the circles when they are spawned?

I understand I can spawn them individually but is there a better way? ( I am using SpriteKit on swift)

Pimgd
  • 5,983
  • 1
  • 30
  • 45
MattJB
  • 13
  • 6
  • What do you mean 'spawn in the middle of the x axis and fhen for the node to spawn all the way down the screen'? – ABakerSmith Jun 05 '15 at 21:26
  • Sorry, I may have meant the y axis as I would these circle nodes to spawn down the middle of the screen in a straight line down. – MattJB Jun 06 '15 at 10:02

1 Answers1

0

You need to learn some basics bruh. Learn about For loops, arrays and arc4random.

        var circleDiameter: CGFloat = 80.0
        for var y = self.frame.height; y > 0; y = y - circleDiameter
        {
            let coloroptions = [UIColor.greenColor(), UIColor.blueColor(), UIColor.redColor()]
            let randomNumber = Int(arc4random_uniform(UInt32(coloroptions.count)))
            let color = coloroptions[randomNumber]
            var rect = CGRectMake(self.frame.width / 2, y, circleDiameter, circleDiameter)
            var circle = SKShapeNode()
            circle.path = UIBezierPath(ovalInRect: rect).CGPath
            circle.fillColor = color
            circle.lineWidth = 0
            circle.physicsBody = SKPhysicsBody(circleOfRadius: circle.frame.width / 2)
            circle.physicsBody?.dynamic = false
            self.addChild(circle)
        }
Jake Crastly
  • 462
  • 3
  • 9