Libgdx box2d issue with dimensions and camera zooming(Libgdx box2d 尺寸和相机缩放问题)
问题描述
Box2D
有问题.我正在制作一个简单的 2D 游戏,玩家向敌人射击.我读到 Box2D 中的 1 个单位相当于 1 米,所以我应该使用小尺寸.我将世界尺寸设置为 160x90,但问题如下:
I've got a problem with Box2D
. I'm making a simple 2D game, with a player shooting to enemies. I read that 1 unity in Box2D is equivalent to 1 meter so i should use little dimensions. I set world dimensions to 160x90 but here are the problems:
使用小尺寸时,我不得不缩放设置为 1280x720 的相机,但如您所见,形状质量大幅下降,而且身体的运动也不再流畅.而且即使世界步速为1/300,最高速度还是太慢了!
Using little dimensions i had to zoom my camera that is set to 1280x720 but as you can see there is a big drop of quality in shapes, and also the movements of bodies are no longer flowing. And the max speed is still too slow even if the world steps at 1/300!
Vsinc
已启用,缩放设置为 0.125,您看到的正方形是每边 10 个单位.
Vsinc
is enabled, zoom is set to 0.125 and the squares you see are 10 units per side.
http://imgur.com/oGYvuNv
这是相机的代码
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.在这里阅读这篇精彩的 文章 和这篇 答案.例如:
Don't use PPM, i know you might have seen a lot of tutorials using PPM but instead use virtual pixels or potato pixel for camera and box2d. Here read this wonderful article and this answer. For example:
OrthographicCamera camera = new OrthographicCamera(20, 11);
这里 20 是 WIDTH
的任意数字,HEIGHT
实际上应该是 WIDTH*Gdx.graphics.getHeight()/Gdx.graphics.getWidth()代码>.您不需要设置任何缩放级别,保持默认即可.
Here 20 is any arbitrary number for WIDTH
and HEIGHT
should be actually WIDTH*Gdx.graphics.getHeight()/Gdx.graphics.getWidth()
.
You don't need to set any zoom level, leave it to default.
这篇关于Libgdx box2d 尺寸和相机缩放问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Libgdx box2d 尺寸和相机缩放问题
基础教程推荐
- Android:对话框关闭而不调用关闭 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01