LibGDX Touch Box2D机身

cod*_*e22 2 android box2d libgdx

我正在使用LibGDX来创建一个新项目.

我想要做的是,我将tmx文件中的物体加载到工作正常的级别.身体也有一个精灵.

问题是,我是否想让用户触摸场景中的某些物体.当他们触摸身体时,他们将能够从场景中删除或删除它.

我不熟悉在libgdx中做这样的事情.虽然我确信它并不复杂.

无论如何我能在LibGDX中做到这一点吗?

编辑:

这是我到目前为止所拥有的.

QueryCallback callback = new QueryCallback() {


    @Override
    public boolean reportFixture(Fixture fixture) {
        // if the hit fixture's body is the ground body
        // we ignore it

        // if the hit point is inside the fixture of the body
        // we report it

        hitBody = fixture.getBody();

        return true;
    }
};

@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
    // TODO Auto-generated method stub
    hitBody = null;


    return false;
}
Run Code Online (Sandbox Code Playgroud)

现在我只是不确定我如何删除被点击的身体..

Vik*_*ain 5

https://github.com/libgdx/libgdx/blob/master/tests/gdx-tests/src/com/badlogic/gdx/tests/Box2DTest.java 使用此链接使用queryAABB选择具有接触点的对象.此代码还提供了如何使用鼠标关节移动对象.如果要删除对象,请确保在世界的步骤周期后删除它们.

编辑:

....
public boolean touchDown (int x, int y, int pointer, int newParam) {
        testPoint.set(x, y, 0);
        camera.unproject(testPoint);
        hitBody = null;
        world.QueryAABB(callback, testPoint.x - 0.1f, testPoint.y - 0.1f, testPoint.x + 0.1f, testPoint.y + 0.1f);

        return false;
}
.....
Run Code Online (Sandbox Code Playgroud)