swift - The Position of SpriteNode in SpriteKit -
i getting start spritekit, , in project. wanna create grids falling sky , form grids map follow:
i created physics world gravity -9.8
and grid, each of them created following constructor , add scene:
class numbertile:skspritenode{ convenience init(xpos:cgfloat, ypos:cgfloat){ var tilecolorarray:nsarray = ["#996666","#a65959","#b34d4d","#bf4040","#cc3333","#d92626","#e61919"] //get random color array var fillcolor:uicolor = uicolor(rgba: tilecolorarray.objectatindex(int(arc4random_uniform(uint32(tilecolorarray.count)))) as! string) var size:cgsize = cgsize(width: 38, height: 38); self.init(color:fillcolor, size:size) self.position = cgpointmake(xpos, ypos) self.anchorpoint = cgpointmake(0,0) self.physicsbody = skphysicsbody( rectangleofsize: cgsize(width: 38,height: 40), center: cgpointmake((cgfloat)(38/2),(cgfloat)(40/2))) self.physicsbody?.mass = 1000 self.physicsbody?.friction = 1.0 self.physicsbody?.allowsrotation = false; } }
after running function drop grids sky. in case 6th column's height different others. happens randomly, not must happen in 6th column, idea?
//update adding tile creation code
func addtileinrow(row: nsinteger){ var xpos:cgfloat = (cgfloat)(self.counter - 1) * (38 + (2)) + (2)/2; var ypos:cgfloat = (self.headersprite.frame.origin.y - self.headersprite.frame.size.height) var tile:numbertile = numbertile(xpos: xpos, ypos: ypos) addchild(tile) }
the counter start 1, when counter larger 7, reset 1 until 8 rows created.
Comments
Post a Comment