So this is pretty weird... I have an abstract BaseScreen. This screen initializes a SpriteBatch on show(). The init() calls the one of the BaseScreen's abstract methods. This draw issue is from using the 'gameView' viewport which is an ExtendViewport
SpriteBatch batch;
@Override
public void show(){
batch = new SpriteBatch();
gameView = new ExtendViewport(SV.V_WIDTH, SV.V_HEIGHT);
hudView = new ScreenViewport();
init();
}
This is what I do in the render function:
@Override
public void render(float delta){
/*
Just in case render is being called more than usual 60 times,
I want to call update only 60 times per second. (SV.STEP = 1/60f)
*/
accum += delta;
while(accum >= SV.STEP){
accum -= SV.STEP;
update();
}
/* Clear Screen */
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT);
/* DRAW WORLD */
batch.setProjectionMatrix(gameView.getCamera().combined);
gameView.apply(true);
batch.begin();
draw(batch, SV.BatchType.World);
batch.end();
/* DRAW UI
batch.setProjectionMatrix(hudView.getCamera().combined);
hudView.apply(true);
batch.begin();
draw(batch, SV.BatchType.UI);
batch.end();*/
}
I have two viewports, one for the game world and one for hud. I use them to set the projection matrix of the batch.
The draw(batch, SV.BatchType.World) command ultimately takes the code to here:
private void drawBody(Batch batch){
Vector2 position = body.getPosition();
//Gdx.app.log(TAG, heart.getWidth() + ", " + heart.getHeight());
batch.draw(heart, position.x-100,position.y-50, h_width*2, h_height*2);
font.draw(batch, "THIS IS A WOOOOOOOOO!", 100, 100);
}
Now this piece of code draws this:
Notice how it doesn't draw the text.
Here's the result with batch.draw only - (font.draw is omitted)
Now the issue becomes 'what type of .draw was called last' and it ignores all of them - For example:
private void drawBody(Batch batch){
Vector2 position = body.getPosition();
//Gdx.app.log(TAG, heart.getWidth() + ", " + heart.getHeight());
batch.draw(heart, position.x-100,position.y-50, h_width*2, h_height*2);
font.draw(batch, "THIS IS A WOOOOOOOOO!", 100, 100);
font.draw(batch, "THIS IS A TEST!", position.x, position.y + 100);
font.draw(batch, "THIS IS A WOOOOOOOOO!", position.x, position.y - 100);
}
Will draw
and this
private void drawBody(Batch batch){
Vector2 position = body.getPosition();
//Gdx.app.log(TAG, heart.getWidth() + ", " + heart.getHeight());
batch.draw(heart, position.x-100,position.y-50, h_width*2, h_height*2);
font.draw(batch, "THIS IS A WOOOOOOOOO!", 100, 100);
font.draw(batch, "THIS IS A TEST!", position.x, position.y + 100);
font.draw(batch, "THIS IS A WOOOOOOOOO!", position.x, position.y - 100);
batch.draw(heart, position.x,position.y, h_width*2, h_height*2);
batch.draw(heart, position.x,position.y+ 100, h_width*2, h_height*2);
}
Will draw
Here is an example with 6 draws, but you have to have a 'throwaway' last .draw
private void drawBody(Batch batch){
Vector2 position = body.getPosition();
//Gdx.app.log(TAG, heart.getWidth() + ", " + heart.getHeight());
batch.draw(heart, position.x-100,position.y-50, h_width*2, h_height*2);
font.draw(batch, "THIS IS A WOOOOOOOOO!", 100, 100);
font.draw(batch, "THIS IS A TEST!", position.x, position.y + 100);
batch.draw(heart, position.x,position.y, h_width*2, h_height*2);
batch.draw(heart, position.x,position.y+ 100, h_width*2, h_height*2);
font.draw(batch, "THIS IS A WOOOOOOOOO!", position.x, position.y - 100);
batch.draw(heart, 10,10, h_width*2, h_height*2);
}
Here's one last thing... the last batch draw... if you try to draw it at 0, 0 -> this happens
Seeking any kind of helpful feedback and/or reason why this may be happening. I'm a newbie with LibGdx and would not shun your feedback on how I decided to use this framework.
Thanks a bunch!