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

/**

 * added by Bruce Yang on 2012.03.09.15.41~

 * 创建乌鸦~

 */

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

    b2Vec2 po = object.position;

    b2BodyDef bodyDef;

    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;

    

    b2PolygonShape shape;

    shape.SetAsBox(0.4f0.1f);

    

    b2FixtureDef fixtDef;

    fixtDef.shape = &shape;

    fixtDef.density = CROW_DENSITY;

    fixtDef.friction = CROW_FRICTION;

    fixtDef.restitution = CROW_RESTITUTION;

    body->CreateFixture(&fixtDef);

    

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

    [sprite setupSchedule];

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

    sprite.tag = TAG_SPRITE_CROW;

    sprite.scale = 1.5f;

    [[BYSingle getInstancespriteRunRepeatAction:sprite animName:ANIMATION_CACHE_CROW_FLY];

    [_single.gameLayer addChild:sprite z:-1];

    body->SetUserData(sprite);

    return body;

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值