ios - SKPhysicsJointSpring between 2 objects that are not direct children of the scene -
i wanted mix 2 tutorials, namely:
http://hub.ae/blog/2014/03/26/soft-body-physics-jellyusing-spritekit/
and
https://developer.apple.com/library/ios/documentation/graphicsanimation/conceptual/spritekit_pg/actions/actions.html (example: centering scene on node part)
i got both working 1 one, i've bug when mix both.
if code starts this:
[self setanchorpoint:cgpointmake(0.5f, 0.5f)]; _myworld = [sknode node]; [self addchild:_myworld]; [self createplayer]; // replaced [self addchild's [_myworld addchild]
then camera follows player there no joints created!
if put [self createplayer]
top , leave [self addchilds]
(because _myworld isn't created yet) there joints working camera doesn't follow player, since player isn't in _myworld.
i leave [self.physicsworld addjoint:joint];
time.
any idea go wrong?
when moved parts _myworld told in apple guide, didn't know had shift anchor points, in scene coordinates.
adding these lines solved problem:
cgpoint p1 = [self.scene convertpoint:cgpointmake(point1.position.x+self.frame.size.width/2, point1.position.y+self.frame.size.height/2) fromnode:_myworld]; cgpoint p2 = [self.scene convertpoint:cgpointmake(point2.position.x+self.frame.size.width/2, point2.position.y+self.frame.size.height/2) fromnode:_myworld];
in attachpoint
function.
Comments
Post a Comment