1

When I attempt to join two SKSpriteNodes with SKPhysicsJointFixed, they separate as if not connected at all. Nothing I do seems to work. Here's my code...

CGPoint position = CGPointMake(100, 100);
CGSize size = CGSizeMake(4, 64);

SKSpriteNode *node1 = [SKSpriteNode spriteNodeWithColor:[SKColor whiteColor] size:size];
node1.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:size];
node1.position = position;

SKSpriteNode *node2 = [SKSpriteNode spriteNodeWithColor:[SKColor whiteColor] size:size];
node2.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:size];
node2.position = position;

[scene addChild:node1];
[scene addChild:node2];

SKPhysicsJointFixed *joint = [SKPhysicsJointFixed jointWithBodyA:node1.physicsBody
                                                            bodyB:node2.physicsBody
                                                          anchor:CGPointMake(100, 100)];
[scene.physicsWorld addJoint:joint];

Thanks in advance.

0x141E
  • 12,613
  • 2
  • 41
  • 54
  • it's working... but try other position for node2, let's say... CGPoint position2 = CGPointMake(100, 120); ... node2.position = position2; – TonyMkenu Jun 19 '14 at 08:21
  • what is not working? please, check my code... but your code it's also ok, just change the node's color :) – TonyMkenu Jun 19 '14 at 08:54

1 Answers1

1

this is my working code....

CGPoint position = CGPointMake(100, 350);
CGPoint position2 = CGPointMake(100, 420);
CGSize size = CGSizeMake(4, 164);

SKSpriteNode *node1 = [SKSpriteNode spriteNodeWithColor:[SKColor whiteColor] size:size];
node1.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:size];
node1.position = position;

SKSpriteNode *node2 = [SKSpriteNode spriteNodeWithColor:[SKColor redColor] size:size];
node2.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:size];
node2.position = position2;

[scene addChild:node1];
[scene addChild:node2];

SKPhysicsJointFixed *joint = [SKPhysicsJointFixed jointWithBodyA:node1.physicsBody
                                                                   bodyB:node2.physicsBody
                                                                  anchor:CGPointMake(node1.position.x, node1.position.y-30)];

[scene.physicsWorld addJoint:joint];
TonyMkenu
  • 7,597
  • 3
  • 27
  • 49