【发布时间】:2012-03-29 00:31:08
【问题描述】:
我想知道是否有办法在 libgdx 中制作 Android 游戏,以便它们都共享相同的 480x800 分辨率。使用 Gdx.graphics.setDisplayMode(480, 800, true) 似乎没有任何改变。创建一个 480 x 800 的 OrthographicCamera 使得游戏是 480 x 800,但不会像我预期的那样放大到全屏并占据整个屏幕。当我在手机上进行测试时,手机只是在 480x800 分辨率的游戏中使用空白空间来填充屏幕的其余部分。这是我正在使用的代码。
public class GameScreen implements Screen {
private Game game;
private OrthographicCamera guiCam;
private SpriteBatch batch;
private Texture texture;
private Rectangle glViewport;
public GameScreen (Game game)
{
this.game = game;
guiCam = new OrthographicCamera(GAME_WIDTH, GAME_HEIGHT);
guiCam.position.set(GAME_WIDTH / 2, GAME_HEIGHT / 2, 0);
batch = new SpriteBatch();
texture = new Texture(Gdx.files.internal("data/c2.png"));
glViewport = new Rectangle(0, 0, GAME_WIDTH, GAME_HEIGHT);
}
@Override
public void render(float delta) {
if (Gdx.input.justTouched()) {
texture = new Texture(Gdx.files.internal("data/c1.png"));
}
GL10 gl = Gdx.graphics.getGL10();
gl.glClearColor(1, 0, 0, 1);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
gl.glViewport((int) glViewport.x, (int) glViewport.y,
(int) glViewport.width, (int) glViewport.height);
guiCam.update();
guiCam.apply(gl);
batch.setProjectionMatrix(guiCam.combined);
batch.begin();
batch.draw(texture, 0, 0, 0, 0, 142, 192);
batch.end();
}
private static final int GAME_WIDTH = 480;
private static final int GAME_HEIGHT = 800;
}
提前致谢。
【问题讨论】: