屏幕尺寸不适合屏幕,因为它通常会
我使用box2D渲染来查看我的图形(我试过使用纹理,我得到完全相同的结果)我的渲染代码如下:屏幕尺寸不适合屏幕,因为它通常会
public void render()
{
long startTime = System.nanoTime();
world.step(Gdx.app.getGraphics().getDeltaTime(), 3, 3);
float updateTime = (System.nanoTime() - startTime)/1000000000.0f;
startTime = System.nanoTime();
float renderTime = (System.nanoTime() - startTime)/1000000000.0f;
GL10 gl = Gdx.app.getGraphics().getGL10();
camera.update();
camera.apply(gl);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
batch.setProjectionMatrix(camera.combined);
renderer.render(world, camera.combined);
batch.begin();
font.setScale(0.020f);
font.draw(batch, "fps:" + Gdx.graphics.getFramesPerSecond() + ", update: " + updateTime + ", render: " + renderTime, 0,
20);
batch.end();
}
它在桌面版本上绝对正常工作,并显示它应该。
然而,当我启动它在我的手机上,我得到这个,这不是我想要的:
,你可以看到它被压扁,只占用的顶部的屏幕。
在libgdx中有错误还是我错过了什么?
编辑:完成创建代码:
Vector2 pouchPos = new Vector2(0, -12);
slingshotListener = new SlingshotListener(pouchPos);
batch = new SpriteBatch();
camera = new OrthographicCamera(32, 48);
Gdx.input.setInputProcessor(slingshotListener);
font = new BitmapFont();
renderer = new Box2DDebugRenderer();
world = new World(new Vector2(0, -10), true);
BodyDef bd = new BodyDef();
ground = world.createBody(bd);
EdgeShape shape = new EdgeShape();
shape.set(new Vector2(-16, -20), new Vector2(16, -20));
FixtureDef fd = new FixtureDef();
fd.shape = shape;
ground.createFixture(fd);
shape.dispose();
Misc.createLine(new Vector2(-3, -16), pouchPos, camera, world).setSensor(true);
Misc.createLine(new Vector2(3, -16), pouchPos, camera, world).setSensor(true);
pic = new Texture(Gdx.files.internal("pong/ball.png"));
我把这个在AndroidManifest.xml,它似乎解决这个问题:
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="13" />
您应该在该XML前面添加4个空格,以便它在答案中显示。 – 2012-03-23 22:53:24
另外,你知道为什么改变预期的版本改变了显示? – 2012-03-23 22:54:19
与仅支持高达480x320的分辨率的miniSdkVersion 3有关,导致我的游戏在分辨率大于480x320的手机上以兼容模式运行。 – Derek 2012-03-24 08:42:25
你如何设置你的视口和摄像机的位置? – 2012-03-22 18:33:53
我认为这是显示分辨率的差异导致两者出现不同。这个问题的答案可能有所帮助:http://*.com/q/9198932/324625即使您的设置有点不同(它看起来不像您在libgdx中使用2D场景图)。重点是您需要居中您的视口并放置您的相机。这些应该在处理'resize()'时完成。 – 2012-03-22 22:44:07