1
votes

I am developing a game with LibGdx. I am using scene2d actors in my game. I have 2 arrows with this body

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());
}

Picture of the body

enter image description here

but, when I drop one arrow above another they overlap instead of colliding. From description of body editor I found that there is a red mark which is the reference point.

How do I make the arrows collide?

1
this is my first question in SOShidil Eringa

1 Answers

4
votes

I found the answer

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

where 90 is the width of arrow.