Search code examples
ioscocos2d-iphonespritebuilder

Physic Spring Joint Worked Unexpectedly


I'm quite new to Sprite Builder. I'm trying Clone Angry Birds with SpriteBuilder > Add Physics using Chipmunk, Part 1. Now I encountered a weird problem.

According to the code, the restLength of spring that joins catapult arm and the square shouldn't be able to be stretched. The square is a invisible CCNode.

_mouseJoint = [CCPhysicsJoint connectedSpringJointWithBodyA:_mouseJointNode.physicsBody bodyB:_catapultArm.physicsBody anchorA:ccp(0, 0) anchorB:ccp(14, 150) restLength:0.f stiffness:3000.f damping:150.f];

Here's my spring(Sorry I don't know how to make a screenshot while dragging the mouse): My Spring

And here's what it should look like: Should Be

It seems the spring in the tutorial can't be stretched, and I didn't see this invisible CCNode in the expected result.

Is this because of the value of anchorB? Actually I don't think so.

All the suggestions will be appreciated. =)


Solution

  • Alright, I got why. I should set the invisible CCNode to Circle and its corner to 0. Also, I should set it to "static"