HOWTO MAKE HANGING CHAINS WITH SPRITE KIT PHYSICS JOINTS

How to build a physical object hanging on chains for your game with SKPhysics and SKPhysicsJointPins. Here is the class code for a free configurable object with chains like in this video

The class can be called like this

The first argument is the position of the left first anchor where the chain will be fixed. „secondAnchorPos“ is doing the same for the right side. „ropeWidth“ configures the length of the chains. „potWidth“ describes the size of the hanging pot in the middle. The height will be scaled automatically. The „game„-argument should be your SKScene where the whole stuff would be added. At last „potId“ should be a unique number, so you can add more of these objects to your Sprite Kit SKScene avoiding naming conflicts.

The physic bodies are arranged with lots of SKPhysicsJointPins as you can see in this debug view.

HOWTO MAKE HANGING CHAINS WITH                                 SPRITE KIT PHYSICS JOINTS

Here comes the complete class code:

 

 

4 thoughts on “HOWTO MAKE HANGING CHAINS WITH SPRITE KIT PHYSICS JOINTS

  1. really cool effect
    rope physics are a cool thing to add in your game
    thanks for sharing thins code

  2. Great blog and great post! I have been working on a sprite kit game in my free time for almost a year now and the main mechanic is using ropes. I occasionally see a bug where the joints break but yours look very stable in this video. I’m looking at your code now to see how you did it differently than I did. Thanks again!

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

*
*
Website