How to make a rope using SpriteKit SKPhysicsJointLimit?

I use the for loop to create sprites with 7 cable links, I can’t figure out how to extract the rope from them using SKPhysicsJointLimit .: '(

-(void)ropeStuff {
    int i ;
    int y;
    SKSpriteNode *ropes;
    SKPhysicsJointLimit * ropeLink;
    NSMutableArray *ropeArray;

    for (i = 0 ; i < 7; ++i) {

        if (i) {
            int x = 16;
            y = (x * i);
            ropes.position = CGPointMake(_cat.position.x, _cat.position.y + (x * i) );
        }
        ropes = [SKSpriteNode node];
        ropes = [SKSpriteNode spriteNodeWithImageNamed:@"rope link.png"];
        ropes.position = CGPointMake(_cat.position.x, _cat.position.y +5);
        ropes.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:1];
        ropes.physicsBody.affectedByGravity = YES;
        ropes.physicsBody.dynamic = YES;
        ropes.name = @"rope";

        [_worldNode addChild:ropes];
        if (i) {
            ropeLink = [SKPhysicsJointLimit jointWithBodyA:ropes.physicsBody          
            bodyB:ropes.physicsBody anchorA:ropes.position anchorB:ropes.position];
            [_worldNode.scene.physicsWorld addJoint:ropeLink];
        }
    }
    }

Thank you all for your help !: D

+4
source share
1 answer

Why are you using SKPhysicsJointLimit? A rope is a group of segments that rotate relative to each other. You must use SKPhysicsJointPin with or without rotation restrictions.

+4
source

All Articles