Draw a SKPhysicsJoint line between two nodes

Draw a SKPhysicsJoint line between two nodes
I’m working with two SKSpriteNode objects and was wondering how to draw a simple line between them. The line should be updating dynamically when objects are moving. I found a simple solution with a SKShapeNode class. Here is the code.

1. Create a SKPhysicsJoint object e.g. SKPhysicsJointSpring and connect objects with each other. Later add this joint to the physicsWorld:

Continue reading

Make Your Characters Come Alive!

If you would like to make your characters come alive and you want do it very simply – here is an example!

First, create NSMutableArray – you need to store all your textures here and use it as a parameter for SKAction’s method animateWithTextures: timePerFrame:.

Of course it is necessary to add Texture Altas to the project. It should look like the screenshot below:

RightDuckTextureAtlasXcodeExample

Continue reading

Working with Collisions and Contacts in Sprite Kit

Collisions and contacts in Sprite KitWhen two bodies are occupying the same place you can make a decision how your game responds. In Sprite Kit you have two kinds of interactions between physics bodies:

– A contact is used when you need to know when two bodies are touching each other.

– A collision is used when you need to decide if your body should strike another body or ignores it.

Contacts and collisions can work independent. It means that you can check contacts even when collisions are disabled.

The categorizations and interactions are each defined by a 32-bit mask. Whenever a potential interaction occurs, the category mask of each body is tested against the contact and collision masks of the other body.

If you want to provide this feature to your game you have to remember about few important things.

Continue reading