android - Libgdx box2d 的尺寸和相机变焦问题

标签 android libgdx box2d dimensions

我在使用 Box2D 时遇到问题。我正在制作一个简单的 2D 游戏,玩家向敌人射击。我读到 Box2D 中的 1 个单位相当于 1 米,所以我应该使用较小的尺寸。我将世界尺寸设置为 160x90 但存在以下问题:

使用小尺寸,我必须缩放设置为 1280x720 的相机,但正如您所看到的,形状质量大幅下降,而且 body 的运动不再流畅。即使世界步长为 1/300,最大速度仍然太慢!

Vsinc 已启用,缩放设置为 0.125,您看到的正方形每边 10 个单位。

/image/iDV7Q.jpg

这是相机的代码

OrthographicCamera camera = new OrthographicCamera(64,32);

这是绘制圆的类的代码

public class JoyCircle implements GraphicalComponent {
public int radius;
public Vector2 position;
ShapeRenderer renderer;
Color color;
OrthographicCamera c;

public JoyCircle(int radius,Vector2 position,OrthographicCamera c,Color color) {
    this.c = c;
    this.color = color;
    this.radius = radius;
    this.position = position;
    renderer = new ShapeRenderer();
    renderer.setProjectionMatrix(c.combined);
}

@Override
public void update() {

}

@Override
public void draw() {
    renderer.begin(ShapeType.Filled);
    renderer.setColor(color);
    renderer.circle(position.x, position.y, radius);
    renderer.end();
}

}

Here is the code of the world draw
public void draw() {
    motionJoystick.draw(); //draws 2 instances of JoyCircle
    renderer.render(world, camera.combined);
}

最佳答案

不要使用 PPM,我知道您可能已经看过很多使用 PPM 的教程,而是使用相机和 box2d 的虚拟像素或马铃薯像素。在这里读到这篇精彩article还有这个answer 。例如:

OrthographicCamera camera = new OrthographicCamera(20, 11);

这里 20 是 WIDTH 的任意数字,HEIGHT 实际上应该是 WIDTH*Gdx.graphics.getHeight()/Gdx.graphics.getWidth() 。 您不需要设置任何缩放级别,将其保留为默认值。

关于android - Libgdx box2d 的尺寸和相机变焦问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34021355/

相关文章:

java - 如何用不同的方法绘制 Sprite libgdx

java - Kyronet 和 androidstudio - TCP 注册期间超时

java - AndEngine Box2d - 如何避免联合 "stretching"?

box2d - box2djs 中的 Spring 效果

java - BOX2D - 将 NULL 常量隐式转换为 'bool' [-Wnull-conversion]

database - Android:是否可以访问与我的应用程序 bundle 在一起的 sqlite 文件?

android - 在 libgdx 中在球体上绘制文本

android - RxAndroidBle 更快地接收通知

android - Scrollview 在 android 中水平和垂直滚动表格

android - 我无法在我的 Android 项目 Android Studio 3.1.3 中使用 volley 库