【问题标题】:LibGdx Physics body editorLibGdx 物理体编辑器
【发布时间】:2013-07-08 14:21:23
【问题描述】:

我正在使用 LibGdx 开发游戏。我在我的游戏中使用了 scene2d 演员。 我的身体有 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());
}

身体图片

但是,当我将一个箭头放在另一个上方时,它们会重叠而不是碰撞。 从正文编辑器的描述中我发现有一个红色标记是参考点。

如何让箭头发生碰撞?

【问题讨论】:

  • 这是我在 SO 中的第一个问题

标签: java box2d libgdx


【解决方案1】:

我找到了答案

GameScreen.shapeLoader.attachFixture(body, type, fd, 90);

其中 90 是箭头的宽度。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-12
    相关资源
    最近更新 更多