How to draw a circle of points that are separate nodes in a fast (SpriteKit)

Hi, I am new to swift and SpriteKit, but now I am working on a game. In my game I want to have a circle of point objects. I looked at everything, but I don’t seem to understand.

What I wanted was a circle of points, each of which was an individual node, which I could use to be able to add animations to each individual node.

Is there a way to draw multiple shapes in a circular pattern like this?

I want it to look like this.

Parametric representation of a circle

I would appreciate any help. I will continue to research and try to talk about them. Thank!

+4
source share
1 answer

:

SpriteKit:

P.S. , , .

func circleOfDots() {
        let circlePath = UIBezierPath(arcCenter: CGPoint(x: 200,y: 200), radius: CGFloat(100), startAngle: CGFloat(0), endAngle:CGFloat(M_PI * 2), clockwise: true)
        let shapeNode = SKShapeNode()
        shapeNode.path = circlePath.CGPath
        shapeNode.position =  CGPoint(x:CGRectGetMidX(self.frame)-200, y:CGRectGetMidY(self.frame)-200)
        //change the fill color
        shapeNode.fillColor = UIColor.clearColor()
        //you can change the stroke color
        shapeNode.strokeColor = UIColor.redColor()
        //you can change the line width
        shapeNode.lineWidth = 6.0
        let one : CGFloat = 1
        let two : CGFloat = 10
        let pattern = [one,two]
        let dashed = CGPathCreateCopyByDashingPath(circlePath.CGPath,nil,0,pattern,2)
        shapeNode.path = dashed
        shapeNode.lineCap = CGLineCap.Round
        self.addChild(shapeNode)
    }

:

enter image description here

:

UIKit

func circleOfDots() {
        let circlePath = UIBezierPath(arcCenter: CGPoint(x: 200,y: 200), radius: CGFloat(100), startAngle: CGFloat(0), endAngle:CGFloat(M_PI * 2), clockwise: true)
        let shapeLayer = CAShapeLayer()
        shapeLayer.path = circlePath.CGPath
        shapeLayer.position = CGPointMake(CGRectGetMidX(self.view.bounds)-200 ,CGRectGetMidY(self.view.bounds)-200 )
        //change the fill color
        shapeLayer.fillColor = UIColor.clearColor().CGColor
        //you can change the stroke color
        shapeLayer.strokeColor = UIColor.redColor().CGColor
        //you can change the line width
        shapeLayer.lineWidth = 6.0
        let one : NSNumber = 1
        let two : NSNumber = 20
        shapeLayer.lineDashPattern = [one,two]
        shapeLayer.lineCap = kCALineCapRound
        self.view.layer.addSublayer(shapeLayer)
    }

:

enter image description here

, , , , .

SpriteKit

func circleOfDots() {
        let radius: CGFloat = 100.0
        let numberOfCircle = 30
        for i in 0...numberOfCircle {

            let circle = SKShapeNode(circleOfRadius: 2 )
            circle.strokeColor = SKColor.clearColor()
            circle.glowWidth = 1.0
            circle.fillColor = SKColor.orangeColor()
            // You can get every single circle by name:
            circle.name = String(format:"circle%d",i)
            let angle = 2 * M_PI / Double(numberOfCircle) * Double(i)

            let circleX = radius * cos(CGFloat(angle))
            let circleY = radius * sin(CGFloat(angle))

            circle.position = CGPoint(x:circleX + frame.midX, y:circleY + frame.midY)
            addChild(circle)
        }
}

:

enter image description here

+12

All Articles