I am using the LibGDX library to render a 3D model in my Android application. Now, I am stuck, where I want to render multiple dynamic texts on to different 3D boxes located on different coordinates of the screen. I am able to render a single text using SpriteBatch
, but I need to render different string values on different boxes.
SpriteBatch spriteBatch = new SpriteBatch();
BitmapFont font = new BitmapFont();
spriteBatch.maxSpritesInBatch = 5;
spriteBatch.setProjectionMatrix(camera.combined.cpy().scale(camera.combined.cpy()
.getScaleX()/25,camera.combined.cpy().getScaleY()/25, 0.8f));
spriteBatch.begin();
font.setColor(1.0f, 0.0f, 0.0f, 1.0f);
float xPos = -90;
int count = 0;
for (Widget widgets : display.getWidgets())
{
float boxWidth = widgets.getBounds().getWidth();
float boxHeight = widgets.getBounds().getHeight();
float boxHeightCenter = widgets.getBounds().getCenterY();
if(count==0)
{
font.draw(spriteBatch, "Hello"+count, xPos, boxHeightCenter-25,
boxWidth, 0, true);
++count;
}
else
{
font.draw(spriteBatch, "Hello"+count, xPos+boxWidth, boxHeightCenter-25,
boxWidth, 0, true);
xPos = xPos+boxWidth;
++count;
}
}
spriteBatch.end();`
The above code renders only one string value. While debugging, the "for" loop is getting traversed, but no positive result is obtained. How do I fix this?