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