0
我有一个简单的LibGdx应用程序和两个精灵。一个是重复以填充背景的简单纹理。这一个工程。另一个是alpha混合的纹理,所以角落看起来比中心更暗。它被拉伸覆盖整个屏幕。出于某种原因,这个出现在错误的位置,只是一个大白盒子。Sprites显示为白色框
这里是我的代码:
public class TestGame extends ApplicationAdapter {
SpriteBatch batch;
boolean showingMenu;
Texture background;
Sprite edgeBlur;
Texture edgeBlurTex;
@Override
public void create() {
showingMenu = true;
batch = new SpriteBatch();
background = new Texture(Gdx.files.internal("blue1.png"));
edgeBlurTex = new Texture(Gdx.files.internal("edge_blur.png"));
edgeBlur = new Sprite(edgeBlurTex);
edgeBlur.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
}
@Override
public void resize(int width, int height) {
super.resize(width, height);
edgeBlur.setSize(width, height);
}
@Override
public void dispose() {
background.dispose();
edgeBlurTex.dispose();
super.dispose();
}
@Override
public void render() {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
drawBackground();
batch.end();
}
private void drawBackground() {
for (float x = 0; x < Gdx.graphics.getWidth(); x += background.getWidth()) {
for (float y = 0; y < Gdx.graphics.getHeight(); y += background.getHeight()) {
batch.draw(background, x, y);
}
}
edgeBlur.draw(batch);
}
}
编辑:
我通过改变绘制命令来修复它:
batch.draw(edgeBlurTex, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
然而的,如果我尝试这样做绘制这些纹理后的任何图纸,如:
ShapeRenderer shapeRenderer = new ShapeRenderer();
shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
shapeRenderer.setColor(0, 0, 0, 1);
float unitHeight = Gdx.graphics.getHeight()/9;
float indent = Gdx.graphics.getWidth()/20;
shapeRenderer.rect(indent, unitHeight, Gdx.graphics.getWidth() - indent * 2, unitHeight);
shapeRenderer.rect(indent, unitHeight * 3, Gdx.graphics.getWidth() - indent * 2, unitHeight);
shapeRenderer.rect(indent, unitHeight * 5, Gdx.graphics.getWidth() - indent * 2, unitHeight);
shapeRenderer.rect(indent, unitHeight * 7, Gdx.graphics.getWidth() - indent * 2, unitHeight);
shapeRenderer.end();
它只是停止工作,并返回画一个白色的盒子。它看起来非常随机,就像是用libgdx严重错误配置的东西。有没有什么办法可以调试这个东西来弄清楚什么是错的?
ok然后尝试用'Gdx.gl.glEnable(GL20.GL_BLEND);'{your_shaperenderer_code}'Gdx.gl.glDisable(GL20.GL_BLEND);' –
也支持Shaperenderer代码 - 当SpriteBatch结束时正在开始Shaperenderer? –
好的,很显然,ShapeRenderer有一个无证的要求,在开始绘制之前需要先前的精灵批次结束?结束SpriteBatch解决了这个问题 - 虽然感觉像LibGdx可以做更多的事情来提醒这些错误,除了在整个屏幕上绘制随机的白色矩形。 – user3690202