我的游戏中有两个不同的实体,我想为每个实体设置不同的固定属性。对于brick
我不希望它反弹,brickFixture.restitution=0.0
但它确实具有弹性效果。是因为我们不能给不同的身体提供不同的装置吗?
b2Body* brick;
b2Body* circle;
我的身体和夹具定义如下:
代表brick
:
b2Body* addBrick(int x,int y,int w,int h,bool dyn=true)
{
b2BodyDef bodydef;
bodydef.position.Set(x*P2M,y*P2M); //Setting body position
if(dyn)
{
bodydef.type=b2_dynamicBody; // dynamic body means body will move
}
brick=world->CreateBody(&bodydef); //Creating box2D body
b2PolygonShape shape; //Creating shape object
shape.SetAsBox(P2M*w,P2M*h);
////////////// Adding Fixtures(mass, density etc) //////////////
brickFixture.shape=&shape;
brickFixture.density=1.0;
brick->CreateFixture(&brickFixture);
return brick;
}
代表circle
b2Body* addCircle(int x, int y,int r, bool dyn = true)
{
b2BodyDef bodydef;
bodydef.position.Set(x*P2M,y*P2M); //Setting body position
if(dyn)
{
bodydef.type=b2_dynamicBody; // dynamic body means body will move
}
circle =world->CreateBody(&bodydef); //Creating box2D body
b2CircleShape shape; //Creating shape object
shape.m_radius = r*P2M;
shape.m_p.Set(0,0);
////////////// Adding Fixtures(mass, density etc) //////////////
circleFixture.shape=&shape;
circleFixture.density=1.0;
circleFixture.restitution = 0.7;
circle->CreateFixture(&circleFixture);
return circle;
}
答案 0 :(得分:0)
我们可以为不同的身体提供不同的固定装置。如果你可以让身体静止然后使它静止,因为默认身体是动态的。你手动设置恢复原状。它可能适合你。