CCPhysicsjoint不保持2个身体完好无损

时间:2014-07-01 11:27:03

标签: cocos2d-x cocos2d-x-3.0

我想在另一个物理体(Fire)之前添加一个粒子体(比如说arrow)。 所以,我使用spring joint来保持它们在20000左右的刚度,但它仍然以正确的方式开始,并且粒子体从箭头中摆脱。这是我的代码:

fire part

CCParticleSystem *explosion= [CCParticleSystem particleWithFile:@"bomb.plist"];
explosion.position = ccpAdd(projectilePos, ccp(16,0));
explosion.physicsBody.mass=1.0;
explosion.physicsBody = [CCPhysicsBody bodyWithCircleOfRadius:16.0    andCenter:explosion.anchorPointInPoints];
explosion.physicsBody.type=CCPhysicsBodyTypeDynamic;
explosion.physicsBody.affectedByGravity=FALSE; 
explosion.physicsBody.allowsRotation=FALSE;  //so that fire flames go upwards only, and not rotate
[physicsWorld addChild:explosion];
explosion.physicsBody.collisionMask=@[];

arrow part

CCSprite *tempSprite;
tempSprite = [CCSprite spriteWithImageNamed:@"arrow3@2x.png"];
[tempSprite setScale:0.05];
[tempSprite setScaleY:0.15];
tempSprite.rotation=rotation;
tempSprite.position=dummyBow.position;
tempSprite.name=[NSString stringWithFormat:@"%@,%d",[lifeOfSprite[1] objectForKey:@"name"],[[lifeOfSprite[1] objectForKey:@"life"] intValue]];
tempSprite.physicsBody = [CCPhysicsBody bodyWithRect:(CGRect){CGPointZero, tempSprite.contentSize} cornerRadius:0]; // 1
tempSprite.physicsBody.collisionGroup = @"playerGroup";
tempSprite.physicsBody.collisionType  = @"projectileCollision";
[physicsWorld addChild:tempSprite z:0];
projectile.physicsBody.mass=100;

now the joint part

[CCPhysicsJoint connectedSpringJointWithBodyA:playerBomb.physicsBody bodyB:projectile.physicsBody anchorA:ccp(1,1) anchorB:ccp(600,0) restLength:0.f stiffness:20000.f damping:60.f];

image loading]![arrow with fire
enter image description here
(debugDraw)
火应该在前面,但弹簧效应从前面摆动

谁能告诉问题在哪里? 提前谢谢。

0 个答案:

没有答案