Tuesday, 15 May 2012

ios - Sprite Kit - SKShapeNode spawned with weird size -



ios - Sprite Kit - SKShapeNode spawned with weird size -

i trying spawn multiple platforms player sprite jump on.

this current code:

var maingroundadded = false //starting ground player run on func addground() { allow groundsize = cgsizemake(self.frame.width/2, 50) allow ground = skshapenode(rectofsize: groundsize) ground.fillcolor = skcolor.browncolor() ground.name = "ground" ground.physicsbody = skphysicsbody(rectangleofsize: groundsize) ground.physicsbody.affectedbygravity = false ground.physicsbody.dynamic = false ground.physicsbody.restitution = 0.0 ground.physicsbody.categorybitmask = groundcategory ground.physicsbody.collisionbitmask = rcategory if (maingroundadded == false) { ground.position = cgpointmake(0, 0) maingroundadded = true } else { ground.position = cgpointmake(self.frame.width+ground.frame.width, 0) } self.addchild(ground) allow move: skaction = skaction.movetox(-ground.frame.width, duration: 4) allow remove = skaction.removefromparent() ground.runaction(skaction.sequence([move, remove])) }

this how spawn ground

override func update(currenttime: cftimeinterval) { /* called before each frame rendered */ var timesincelast: cftimeinterval = currenttime - self.lastupdatetimeinterval self.lastupdatetimeinterval = currenttime if (timesincelast > 1) { timesincelast = 1.0 / 60.0 self.lastupdatetimeinterval = currenttime } self.updatewithtimesincelastupdate(timesincelast) } func updatewithtimesincelastupdate(timesincelast: cftimeinterval) { self.lastspawntimeinterval = self.lastspawntimeinterval + timesincelast if (self.lastspawntimeinterval > 1.5) { self.lastspawntimeinterval = 0 self.addground() } }

the ground not big rest of ground spawned. how should prepare this?

ios sprite-kit swift

No comments:

Post a Comment