ios - How to draw a circle of dots that are individual nodes in swift (SpriteKit) -


hi new swift , spritekit have been working on game. in game, want have circle of dot objects. have looked cannot seem figure out.

what wanted circle of dots each individual node use able add animations each individual node.

is there way draw multiple shapes in circular pattern this?

i want kind of this.

parametric presentation of circle

i appreciate , help. continue research , try , figure stuff out. thanks!

you can draw circle of dots few lines of code:

spritekit:

p.s. change pattern parameters obtain want exactly..

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 fill color         shapenode.fillcolor = uicolor.clearcolor()         //you can change stroke color         shapenode.strokecolor = uicolor.redcolor()         //you can change line width         shapenode.linewidth = 6.0         let 1 : cgfloat = 1         let 2 : 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)     } 

result:

enter image description here

or traditional code:

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 fill color         shapelayer.fillcolor = uicolor.clearcolor().cgcolor         //you can change stroke color         shapelayer.strokecolor = uicolor.redcolor().cgcolor         //you can change line width         shapelayer.linewidth = 6.0         let 1 : nsnumber = 1         let 2 : nsnumber = 20         shapelayer.linedashpattern = [one,two]         shapelayer.linecap = kcalinecapround         self.view.layer.addsublayer(shapelayer)     } 

result:

enter image description here

finally, if want draw every single shape make animation can use mathematical alghoritm this..

spritekit:

func circleofdots() {         let radius: cgfloat = 100.0         let numberofcircle = 30         in 0...numberofcircle {              let circle = skshapenode(circleofradius: 2 )             circle.strokecolor = skcolor.clearcolor()             circle.glowwidth = 1.0             circle.fillcolor = skcolor.orangecolor()             // can every single circle 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)         } } 

the result:

enter image description here


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -