精灵图像出现拉伸且质量差,无法进入正确位置 GDXLib
Sprite image appears stretched and quality is poor, can't get in correct position GDXLib
我对编程还很陌生,所以请多多包涵...
我正在制作一款 2d 基本游戏,只是为了在 android 工作室练习编程,但我无法将我的精灵放到屏幕上的正确位置。此外,当我绘制精灵时,它看起来被拉伸并且质量很差。感谢您的帮助!
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();
}
你需要保持原来的width/height比例:
不要将其缩放到屏幕尺寸的一半,而是像这样定义缩放比例:
float scaleFactor = 2.0f;
batch.draw(ball, 0,0, ball.getWidth()*scaleFactor, ball.getHeight*scaleFactor);
如果您的图像是 "blurry",并且您希望单个像素保持清晰,请尝试像这样加载纹理:
ball = new Texture("ball2.png");
ball.setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
这会在缩放纹理时阻止(默认)线性插值。
我对编程还很陌生,所以请多多包涵...
我正在制作一款 2d 基本游戏,只是为了在 android 工作室练习编程,但我无法将我的精灵放到屏幕上的正确位置。此外,当我绘制精灵时,它看起来被拉伸并且质量很差。感谢您的帮助!
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();
}
你需要保持原来的width/height比例:
不要将其缩放到屏幕尺寸的一半,而是像这样定义缩放比例:
float scaleFactor = 2.0f;
batch.draw(ball, 0,0, ball.getWidth()*scaleFactor, ball.getHeight*scaleFactor);
如果您的图像是 "blurry",并且您希望单个像素保持清晰,请尝试像这样加载纹理:
ball = new Texture("ball2.png");
ball.setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
这会在缩放纹理时阻止(默认)线性插值。