I have been fiddling with this topic for about three months now. I thought it was just a temporary bug Apple would fix soon and postponed it to the end of development. Now my game is almost finished and I still could not find a good workaround:
If I have a SKShapeNode
and add a physicsbody to it, I cannot use the setPosition:(CGPoint)
method to change the position anymore. My object gets always placed at (0,0) of its parent view.
I have tried setting the position inside the didSimulatePhysics
method, to make sure all physic calculation were done.
I tried using SKAction
to move the node and other suggestions from similar questions here. None worked as desired.
The only (kind of) working solution for me is to use this workaround method:
- (void)setPositionWorkaround:(CGPoint)p {
CGVector vel = self.physicsBody.velocity;
CGFloat angVel = self.physicsBody.angularVelocity;
SKPhysicsBody *temp = self.physicsBody;
self.physicsBody = nil;
[self setPosition:p];
[self setPhysicsBody:temp];
[self.physicsBody setVelocity:vel];
[self.physicsBody setAngularVelocity:angVel];
}
Strangely this method works only once. Every additional time I call this method the position is set to the first call parameter even though there is no data left from the initial call. I checked the parameters and the coordinate systems countless times.
Did someone run into the same problem and found a working solution?