swift - How Make a Sprite Node Rotate Around Another Node? (One More Line) -


so, trying challenge self recreating popular app store game, one more line using spritekit , swift 3; however, having big issue.

1)how node rotate around node when user tapping

2) want node continue moving in same direction facing when user releases finger (hope makes sense...).

kinda this

enter image description here

in gamescene.sks created center node rotating , player. did this:

 override func touchesbegan(_ touches: set<uitouch>, event: uievent?) {     player.move(toparent: center) }  override func touchesended(_ touches: set<uitouch>, event: uievent?) {     player.move(toparent: self) }  override func update(_ currenttime: timeinterval) {     let dx = 5 * cos(player.zrotation)     let dy = 5 * sin(player.zrotation)     player.physicsbody?.applyimpulse(cgvector(dx: dx, dy: dy))  } 

player moves right , when tap circles around node, when release continues move right.

enter image description here

i know going wrong. appreciated. thanks!

i'm not sure understand looking for, if want sprite rotate evenly around centre sprite, add centre sprite, centre sprite (invisible) , add outer sprite invisible centre sprite. rotate 2 centre sprites. adjust outerobject's x position bring outerobject closer or further centre object.

import spritekit import gameplaykit  class gamescene: skscene {      override func didmove(to view: skview) {          anchorpoint = cgpoint(x: 0.5, y: 0.5)          let centerobject = skspritenode(texture: nil, color: uicolor.blue, size: cgsize(width: 20, height: 20))         addchild(centerobject)          let invisibleparent = skspritenode()         addchild(invisibleparent)          let outerobject = skspritenode(texture: nil, color: uicolor.red, size: cgsize(width: 50, height: 50))         outerobject.position.x = 100         invisibleparent.addchild(outerobject)          centerobject.run(skaction.repeatforever(skaction.rotate(byangle: 1, duration: 1)))         invisibleparent.run(skaction.repeatforever(skaction.rotate(byangle: -1, duration: 1)))      }      } 

enter image description here


Comments