Search code examples
iosobjective-ccocoa-touchsprite-kitgame-physics

SKPhysicsJointPin pin position


I'm trying to understand SKPhysicsJointPin a bit better, specifically the anchor point parameter.

I understand that the anchor point is the position in the parent node of the two physics bodies concerned. What I don't understand at which point in the participating bodies does the pin go through and if there is a way to control that.

To make myself clear, say I'm making a clock with hands so the pin should go in the middle of the circle but for the hands is should go through the edge. So how can you control that.

Thanks a bunch.


Solution

  • Documentation is pretty lacking for these. To use the clock reference, and since you obviously know the code, I'll give you the English breakdown:

    1. add 2 clock hand sprites to the scene
    2. set both anchor points on the clock hand sprites to (.5,0)
    3. position both sprites at (100,100)
    4. create 2 physics bodies, add them to each clock hand
    5. create the SKPhysicsJointPin, use anchor point (100,100)
    6. add the joint to the scene

    You should in theory, now have 2 clock hands, able to spin via their own anchor points around the point in the scene at (100,100).