【发布时间】:2020-08-16 14:33:05
【问题描述】:
我正在 LibGDX 中制作一个原型项目,并且我正在使用 Box2D 进行物理。 我创建了一张地图并向他添加了一些碰撞,我也添加了具有圆形形状的实体。 这些圆圈在 Box2D 的世界中正确定位,但我想固定到它们的纹理是基于其他坐标,来自我认为的用户相机。 这是结果:
我在“实体”基类中的渲染方法
public void update() {
handleInput();
}
public void render(SpriteBatch batch) {
update();
batch.begin();
batch.draw(texture, body.getPosition().x, body.getPosition().y);
batch.end();
}
BaseMap 类中的渲染方法
private void update(OrthographicCamera camera) {
camera.position.x = player.getPosition().x;
camera.position.y = player.getPosition().y;
world.step(1/60f, 6, 2);
}
public void render(OrthographicCamera camera, SpriteBatch batch) {
update(camera);
renderer.setView(camera);
batch.begin();
renderer.render();
batch.end();
for(Entity entity : entities) {
entity.render(batch);
}
}
这里的渲染器是一个OrthogonalTiledMapRenderer
【问题讨论】:
-
感谢您分享您的代码。那里有问题吗?
-
我需要将实体的 Box2D 主体与它们的纹理相连接。参考地图本身和参考相机的纹理来渲染身体。如您所见,有些纹理超出了地图的限制,即使它们的身体动作相同
-
body 是空的圆圈,Box2D 的调试模式
标签: java libgdx game-development