我在这个站点上找到了类似的问题,但答案似乎并没有真正帮助解决问题。在大多数情况下,解决方法是编写将像素数转换为米的方法,并使用比例因子。我尝试了这个方法,但所有东西都错位了并且大小不正确。这对我来说似乎是合理的,因为数字已经更改但意义相同。
我想知道是否有一种方法可以使像素表示更少的米,这样一切都会在同一位置上具有相同的(像素)大小,但表示更少的米。如果您有其他想法可能会有所帮助,我也很想听听。
以下是我用来创建摄像机的代码。
width = Gdx.graphics.getWidth() / 5;
height = Gdx.graphics.getHeight() / 5;
camera = new OrthographicCamera(width, height);
camera.setToOrtho(false, 1628, 440);
camera.update();
这是我用来创建对象的方法:
public void Create(float X, float Y, float Width, float Height, float density, float friction, float restitution, World world){
//Method to create an item
width = Width;
height = Height;
polygonDef = new BodyDef();
polygonDef.type = BodyType.DynamicBody;
polygonDef.position.set(X + (Width / 2f), Y + (Height / 2f));
polygonBody = world.createBody(polygonDef);
polygonShape = new PolygonShape();
polygonShape.setAsBox(Width / 2f, Height / 2f);
polygonFixture = new FixtureDef();
polygonFixture.shape = polygonShape;
polygonFixture.density = density;
polygonFixture.friction = friction;
polygonFixture.restitution = restitution;
polygonBody.createFixture(polygonFixture);
}
要创建一个项目,例如表格,在这里我使用以下代码:
Table = new Item();
Table.Create(372f, 60f, 152f, 96f, 1.0f, 0.2f, 0.2f, world);
使用以下方法在项目上绘制Sprites:
public void drawSprite(Sprite sprite){
polygonBody.setUserData(sprite);
Utils.batch.begin();
if(polygonBody.getUserData() instanceof Sprite){
Sprite Sprite = (Sprite) polygonBody.getUserData();
Sprite.setPosition(polygonBody.getPosition().x - Sprite.getWidth() / 2, polygonBody.getPosition().y - Sprite.getHeight() / 2);
Sprite.setRotation(polygonBody.getAngle() * MathUtils.radiansToDegrees);
Sprite.draw(Utils.batch);
}
Utils.batch.end();
}
精灵还具有像素大小。
使用这些方法可以在正确的位置显示图像,但一切都移动得很慢。 我在想如何或者是否需要改变这个来使对象正确地移动或者更少。提前感谢。