Currently working on my first game, though running into some problems with libgx and screen aspect ratio.
What I have is a Stage which contains things like menu buttons etc, and the rest of the game is pretty much sprites being drawn with via SpriteBatch. To avoid having multiple SpriteBatches and cameras, I have re-used the ones that are created when Stage is created.
stage = new Stage(WIDTH, HEIGHT, true); // keep aspect ratio batch = stage.getSpriteBatch(); camera = (OrthographicCamera) stage.getCamera(); // move camera so 'active' screen is centred stage.getCamera().translate(-stage.getGutterWidth(), -stage.getGutterHeight(), 0);
Anything that is Stage/Actor related is drawn fine - all goes within the aspect ratio adjusted boundaries.
The problem I'm having is anything that drawn via SpriteBatch, seems to ignore this viewport that is defined by Stage and can be visible outside of the Stage area.
batch.begin(); ... sirWuffles.draw(batch); ... batch.end();
For example, in the above, if Sir Wuffles is generated outside of the defined WIDTH/HEIGHT it might still appear in the "gutters" of the screen.
Tried to explain it in the below screenshot. It's an exaggerated screen ratio to make the gutters large. I've also covered most of the gutter area in the blue/cyan rectangle so they are very obvious.
Does anyone know what is happening? and how to fix it?
Currently, my "fix" is to use ShapeRenderer to draw rectangles that correspond to the gutters on top of the sprites...