/**
* 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.4f, 0.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 getInstance] spriteRunRepeatAction:sprite animName:ANIMATION_CACHE_CROW_FLY];
[_single.gameLayer addChild:sprite z:-1];
body->SetUserData(sprite);
return body;
}
转载于:https://www.cnblogs.com/yang3wei/archive/2012/03/20/2739840.html
/**
* 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.4f, 0.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 getInstance] spriteRunRepeatAction:sprite animName:ANIMATION_CACHE_CROW_FLY];
[_single.gameLayer addChild:sprite z:-1];
body->SetUserData(sprite);
return body;
}