java Sprite图像出现拉伸且质量差,无法获得正确的位置GDXLib
我对编程很陌生,所以请容忍我在这里
我正在制作一个2d基本游戏,只是为了在安卓 studio中练习编程,但无法将我的精灵放在屏幕上的正确位置。另外,当我绘制精灵时,它看起来是拉伸的,质量非常差。感谢您的帮助
public class MyGdxGame extends ApplicationAdapter {
SpriteBatch batch;
Texture background;
Texture ball;
@Override
public void create () {
batch = new SpriteBatch();
background = new Texture("gamebackground.png");
ball = new Texture("ball2.png");
}
@Override
public void render () {
batch.begin();
batch.draw(background, 0,0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
batch.draw(ball, 0,0, Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);
batch.end();
}
# 1 楼答案
您需要保持原始的宽高比:
与其将其缩放到屏幕大小的一半,不如这样定义缩放:
如果图像“模糊”,并且希望各个像素保持清晰,请尝试这样加载纹理:
这将防止缩放纹理时(默认)线性插值