我创建了一个体,我创建了两个独立的固定装置,一个固定装置创建一个矩形形状,另一个固定装置创建一个圆形。但是当我使用.createfixture时,它将圆圈放在矩形的中心,我希望圆形在矩形的顶部,就像火柴一样。
这是我的代码不知道该做什么......
rectangleBodyDef = new BodyDef();
rectangleBodyDef.type = BodyType.DynamicBody;
rectangleBodyDef.position.set(10,20);
rectangleBody = world.createBody(rectangleBodyDef);
rectangleBodyShape = new PolygonShape();
rectangleBodyShape.setAsBox(2f, 0.75f);
rectangleBodyFixtureDef = new FixtureDef();
rectangleBodyFixtureDef.shape = rectangleBodyShape;
rectangleBodyFixtureDef.restitution = 0.8f;
rectangleBody.createFixture(rectangleBodyFixtureDef);
/**********************CREATING THE SECOND BODY (CIRCLE BODY) ************/
circleShape = new CircleShape();
circleShape.setRadius(0.75f);
circleFixtureDef = new FixtureDef();
circleFixtureDef.shape = circleShape;
circleFixtureDef.restitution = 0.8f;
rectangleBody.createFixture(circleFixtureDef);
答案 0 :(得分:1)
Fixture Definitions相对于身体位置,将CircleShape位置设置为略高于矩形的位置:
CircleShape circleShape = new CircleShape();
circleShape.setRadius(0.75f);
circleShape.setPosition(new Vector2(0,2)); //<------Add this
FixtureDef circleFixtureDef = new FixtureDef();
circleFixtureDef.shape = circleShape;
circleFixtureDef.restitution = 0.8f;
rectangleBody.createFixture(circleFixtureDef);
答案 1 :(得分:0)
circleFixtureDef的位置相对于rectangleBody的位置。将circleFixtureDef的位置设置为0,0以外的其他值。