我正在使用 LibGDX 创建一个新项目。
我想做的是,我将 tmx 文件中的主体加载到工作正常的关卡中。尸体也有一个 Sprite 。
问题是,我想让用户触摸场景中的某些 body 。当他们触摸 body 时,他们将能够将其删除或从场景中移除。
我不太熟悉在 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;
}
现在我只是不确定如何删除被点击的主体..
最佳答案
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;
}
.....
关于android - LibGDX Touch Box2D 体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19092023/