I am attempting to use the following code


So that when the menu is accessed, a transparent background appears. The problem I am facing is that when I try to do this the objects rendered by the SpriteBatch seem to misbehave. Upon further research i found that attempting to nest that code within SpriteBatch.begin() and SpriteBatch.end() is the cause of that. However, If I try to place the code after the SpriteBatch.end(), because the SpriteBatch has ended the objects rendered by it do not appear behind the transparent rectangle. (I tried assigning SpriteBatch and Shaperender a different camera, however, that didn't fix the problem.) How can I fix this or find another way to implement the transparent background for the menu.

  • \$\begingroup\$ You can end the spriteBatch and start it again later. \$\endgroup\$ – dimitris93 Jul 20 '15 at 6:18

As mentioned above, you can start and stop a SpriteBatch in the same draw-method, also for transparency you need to enable BLEND. Here's what I did with one of my UIs.


    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

    shapeRenderer.setColor(new Color(1, 1, 1, 0.1f));
    shapeRenderer.rect(screenMargin + innerScreenMargin, screenMargin+innerScreenMargin + 5*(cellItemHeight+cellMargin+innerCellBorder)-innerCellBorder-cellMargin + innerScreenMargin, (innerCellBorder + innerCellWidth+cellMargin) * 10 - innerCellBorder-cellMargin, 380);


    ... more batchstuff
  • \$\begingroup\$ Thank you, For some reason when I attempted to stop and restart the batch, I got some funky results. The work around was adding a grey rectangle with the appropriate opacity to my sprite sheet and drawing it with the batch where I needed it. \$\endgroup\$ – Ayman Elmubark Jul 23 '15 at 17:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.