i have simple libgdx application 2 sprites. 1 simple texture repeated fill background. 1 works. other texture alpha blended corners darker center. stretched cover entire screen. reason, 1 appears in wrong location , big white box.
here code:
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() { (float x = 0; x < gdx.graphics.getwidth(); x += background.getwidth()) { (float y = 0; y < gdx.graphics.getheight(); y += background.getheight()) { batch.draw(background, x, y); } } edgeblur.draw(batch); } }
edit:
i fixed changing draw command to:
batch.draw(edgeblurtex, 0, 0, gdx.graphics.getwidth(), gdx.graphics.getheight());
however if attempt drawing after drawing these textures, such as:
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();
it stops working , goes drawing white box. seems random, misconfigured libgdx. there way debug thing work out wrong?
you should add enableblending
before blended texture draw
batch.enableblending(); edgeblur.draw(batch); batch.disableblending();
you can try set batch blending func using setblendfunction method after batch created
update due edit:
the spritebatch should ended when starting shaperenderer
Comments
Post a Comment