i attempting center camera on sknode in spritekit. in update function have following:
override func update(currenttime: nstimeinterval) { if self.camera != nil { self.camera!.position = cgpointmake(cgrectgetmidx(super.frame) / 10, waypoints.last!.y) self.centeronnode(self.camera!) } } this centeronnode function:
func centeronnode(node: sknode) { let camerapositioninscene: cgpoint = node.scene!.convertpoint(node.position, fromnode: node.parent!) node.parent!.position = cgpoint(x:node.parent!.position.x - camerapositioninscene.x, y:node.parent!.position.y - camerapositioninscene.y) } this how apple suggests centering camera on node (note these in world sknode). sort of works; centers camera, doesn't update fast enough. produces following effect (note 'cgrectgetmidx(super.frame) / 10' center of screen in case, , 'waypoints.last!.y' y position of apex of line): http://gyazo.com/95f02f98e5707b0065e74f90ac547139
as can see camera moving, line moving faster. i'm not sure why occurring, because shouldn't camera move @ same speed line?
edit: i'm adding/updating waypoints array in separate function called every 0.5 seconds using this:
nstimer.scheduledtimerwithtimeinterval(0.05, target: self, selector: "addpoint", userinfo: nil, repeats: true) however if update camera position in addpoint function, same effect still occurs.
Comments
Post a Comment