我正在使用 LibGdx 开发游戏。我在我的游戏中使用 scene2d Actor 。 这个 body 我有2支箭
private void creatBody() {
BodyDef bd = new BodyDef();
bd.position.set(getX(), getY());
bd.type = BodyType.DynamicBody;
FixtureDef fd = new FixtureDef();
fd.density = 15f;
fd.friction = 0.6f;
fd.restitution = 0.02f;
if (body != null)
removeBodySafely(body);
body = world.createBody(bd);
body.setTransform(body.getWorldCenter(), MathUtils.degreesToRadians
* getRotation());
GameScreen.shapeLoader.attachFixture(body, type, fd, 1);
}
public void draw(SpriteBatch batch, float parentAlpha) {
setRotation(MathUtils.radiansToDegrees * body.getAngle());
setPosition(body.getPosition().x, body.getPosition().y);
TextureRegion keyFrame = GameScreen.getAtlas("arrows").findRegion(type);
batch.draw(keyFrame, getX(), getY(), 0, 0, getWidth(), getHeight(),
1, 1, getRotation());
}
尸体图片
但是,当我将一个箭头放在另一个箭头上方时,它们会重叠而不是碰撞。 从body editor的描述中我发现有一个红色标记是引用点。
如何让箭头碰撞?
最佳答案
我找到了答案
GameScreen.shapeLoader.attachFixture(body, type, fd, 90);
其中 90 是箭头的宽度。
关于java - LibGdx 物理体编辑器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17529049/