【发布时间】:2014-05-28 15:15:56
【问题描述】:
我是 Libgdx 的新手。我试图制作像素艺术游戏,但我遇到了问题。当我用纹理渲染精灵时,像素被变形拉伸(我在第二张图像上添加了红色箭头)。 我制作了 400x400 的窗口并按 1:1 比例缩放精灵以适应屏幕宽度(精灵宽度 = 屏幕宽度,精灵高度 = 屏幕宽度)
图片:
这是主游戏类的代码:
public class Pixel implements ApplicationListener {
SpriteBatch batch;
Texture testTexture;
Sprite testSprite;
int w;
int h;
@Override
public void create() {
batch = new SpriteBatch();
testTexture = new Texture(Gdx.files.internal("test.png"));
testSprite = new Sprite(testTexture);
testSprite.setSize(w, w);
}
@Override
public void render() {
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
testSprite.draw(batch);
batch.end();
}
@Override
public void resize(int width, int height) {
w = width;
h = height;
create();
}
@Override
public void pause() {
// TODO Auto-generated method stub
}
@Override
public void resume() {
// TODO Auto-generated method stub
}
@Override
public void dispose() {
// TODO Auto-generated method stub
}
}
这是桌面入门类:
public class DesktopLauncher {
public static void main(String[] arg) {
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
config.width = 400;
config.height = 400;
new LwjglApplication(new Pixel(), config);
}
}
【问题讨论】:
标签: java android libgdx desktop