I've created a SpriteKit Scene with physics bodys. This is working quite well. I'm also scrolling the scene around, using the Apple best practice with a "camera node".
My scenes node tree is like that:
Scene
|- World
|- Camera node
|- Game nodes with physics bodys
My Problem is, during the game I create new nodes with new joints (mostly fixed joints) dynamically. At that point, the world node has a different position than in the beginning (eg.: at start (0,0), during the game (1000,500)..) Now, the anchorpoint for the fixed joints is not at the position I want it to, it's somewhere in the scene.
I assume, the coordinate system of the scene is different to the coordinate system of the physics engine.
For the anchor Point, I use the following conversion:
[world.scene convertPoint:node.position fromNode:node.parent];
I want to set the anchorpoint at the position of "node". After moving the world node, the calculation of the anchorpoint is not working anymore.
Thanks for your help!
Greetz - Nekro
Update:
Code to center scene on the Player
- (void)centerOnNode:(SKNode*)node {
CGPoint cameraPositionInScene = [node.scene convertPoint:node.position fromNode:node.parent];
node.parent.position = CGPointMake(node.parent.position.x - cameraPositionInScene.x, node.parent.position.y - cameraPositionInScene.y);
}
[world convertToPoint:node.position toNode:world.parent]
. Also, make surenode.position
is in world coordinates (it should be) and thecollisionBitMask
s are set so the two bodies don't collide with each other. – 0x141E