Box2d - 拖放对象后如何创建简单的减速? (Actionscript 3)

时间:2011-01-08 16:10:05

标签: flex flash actionscript-3 box2d

所以我需要的是简单的 - 如何使用flex 4和AS3创建一个可拖放的圆圈并使用Box2d让它在拖动方向上飞得更多而不是停止?

2 个答案:

答案 0 :(得分:3)

您可能希望确保关闭重力(两个维度都为零),例如

var gravity:b2Vec2 = new b2Vec2 (0.0, 0.0);

然后让摩擦减慢。

答案 1 :(得分:3)

使用LinearDamping

这就是我在自上而下射击游戏中使用它的方法,如果线速度停止施加,它会减慢物体的速度。

//Body is created using body definition
var b:b2Body = GameCore.environment.world.CreateBody(bodyDef);

//Fixture definition holds data such as density, friction and shape
var fixtureDef:b2FixtureDef;
fixtureDef = new b2FixtureDef();

//Define vertices etc in polygon shape
var shape:b2CircleShape;
shape = new b2CircleShape(Values.ptm(_diameter / 2));

//Assign values
fixtureDef.shape = shape;
fixtureDef.density = 1.5;
fixtureDef.friction = 0.3;
fixtureDef.restitution = 0.45;

//Add fixture to appropriate body
b.CreateFixture(fixtureDef);    

//Movement Physics Settings
b.SetLinearDamping(_linearDamping);
b.SetAngularDamping(_angularDamping);