如何使用SpriteKit的SKPhysicsJointLimit制作绳子?

4

我正在使用for循环创建7个绳索链接精灵,但不知道如何使用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];
        }
    }
    }

感谢大家的帮助! :D

你正在连接相同的节点(绳索与绳索)。你需要保存前一个节点并连接前一个节点和当前节点。顺便说一下,你应该设置ropeLink的maxmiumLength属性。 - 0x141E
1个回答

4

您为什么要使用SKPhysicsJointLimit?绳子是由相对旋转的一组线段构成的。您应该使用带有或不带旋转限制的SKPhysicsJointPin。


但是如果您使用SKPhysicsJointPin,绳子将具有“弹性”行为。这并不能很好地模拟绳子的行为。 - GeneCode

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接