b2RopeJoint连接的物体摆动幅度夸张的解决办法——设置线性阻尼

/**

* added by Bruce Yang on 2012.03.09.15.41~

*创建乌鸦~

*/

-(b2Body*) createCrow:(BYObject*)object {

b2Vec2po = object.position;

b2BodyDefbodyDef;

bodyDef.type=b2_dynamicBody;

bodyDef.position.Set(po.x, po.y);

b2Body*body =_single.gameSceneWorld->CreateBody(&bodyDef);

body->SetFixedRotation(true);

/**

*https://love2d.org/wiki/Body:getLinearDamping

* Body:getLinearDamping

* Gets the linear damping(线性阻尼) of the Body.

*The linear damping is the rate of decrease of the linear velocity over time.

*A moving body with no damping and no external forces will continue moving indefinitely,

*as is the case in space. A moving body with damping will gradually stop moving.

*

*Damping is not the same as friction - they can be modelled together.

*However, only damping is provided by Box2D (and LOVE).

*/

/**

* 2012.03.15.11.20, added by Bruce Yang, adviced by Eric Zhu~

*相当的有效啊,乌鸦不再烦人的摆来荡去了~

*/

body->SetLinearDamping(0.8f);

body->m_isCuttable=false;

b2PolygonShapeshape;

shape.SetAsBox(0.4f,0.1f);

b2FixtureDeffixtDef;

fixtDef.shape= &shape;

fixtDef.density=CROW_DENSITY;

fixtDef.friction=CROW_FRICTION;

fixtDef.restitution=CROW_RESTITUTION;

body->CreateFixture(&fixtDef);

BYSpriteCrow*sprite = [BYSpriteCrowspriteWithSpriteFrameName:@"animCrow0.png"];

[spritesetupSchedule];

sprite.position=ccp(po.x*PTM_RATIO, po.y*PTM_RATIO);

sprite.tag=TAG_SPRITE_CROW;

sprite.scale=1.5f;

[[BYSinglegetInstance]spriteRunRepeatAction:spriteanimName:ANIMATION_CACHE_CROW_FLY];

[_single.gameLayeraddChild:spritez:-1];

body->SetUserData(sprite);

returnbody;

}


/**

* added by Bruce Yang on 2012.03.09.15.41~

*创建乌鸦~

*/

-(b2Body*) createCrow:(BYObject*)object {

b2Vec2po = object.position;

b2BodyDefbodyDef;

bodyDef.type=b2_dynamicBody;

bodyDef.position.Set(po.x, po.y);

b2Body*body =_single.gameSceneWorld->CreateBody(&bodyDef);

body->SetFixedRotation(true);

/**

*https://love2d.org/wiki/Body:getLinearDamping

* Body:getLinearDamping

* Gets the linear damping(线性阻尼) of the Body.

*The linear damping is the rate of decrease of the linear velocity over time.

*A moving body with no damping and no external forces will continue moving indefinitely,

*as is the case in space. A moving body with damping will gradually stop moving.

*

*Damping is not the same as friction - they can be modelled together.

*However, only damping is provided by Box2D (and LOVE).

*/

/**

* 2012.03.15.11.20, added by Bruce Yang, adviced by Eric Zhu~

*相当的有效啊,乌鸦不再烦人的摆来荡去了~

*/

body->SetLinearDamping(0.8f);

body->m_isCuttable=false;

b2PolygonShapeshape;

shape.SetAsBox(0.4f,0.1f);

b2FixtureDeffixtDef;

fixtDef.shape= &shape;

fixtDef.density=CROW_DENSITY;

fixtDef.friction=CROW_FRICTION;

fixtDef.restitution=CROW_RESTITUTION;

body->CreateFixture(&fixtDef);

BYSpriteCrow*sprite = [BYSpriteCrowspriteWithSpriteFrameName:@"animCrow0.png"];

[spritesetupSchedule];

sprite.position=ccp(po.x*PTM_RATIO, po.y*PTM_RATIO);

sprite.tag=TAG_SPRITE_CROW;

sprite.scale=1.5f;

[[BYSinglegetInstance]spriteRunRepeatAction:spriteanimName:ANIMATION_CACHE_CROW_FLY];

[_single.gameLayeraddChild:spritez:-1];

body->SetUserData(sprite);

returnbody;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值