gpt4 book ai didi

java - LibGdx 物理体编辑器

转载 作者:行者123 更新时间:2023-11-29 03:32:24 25 4
gpt4 key购买 nike

我正在使用 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());
}

尸体图片

enter image description here

但是,当我将一个箭头放在另一个箭头上方时,它们会重叠而不是碰撞。从body editor的描述中我发现有一个红色标记是引用点。

如何让箭头碰撞?

最佳答案

我找到了答案

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

其中 90 是箭头的宽度。

关于java - LibGdx 物理体编辑器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17529049/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com