Skip to main content
Grammar, punctuaton and format
Source Link
Gnemlock
  • 5.3k
  • 5
  • 30
  • 60

I am using LibGdxthe LibGDX library to render 3da 3D model in my Android Applicationapplication. Now i, I am stuck, where iI want to render multiple dynamic texttexts on to different 3D boxes located on different coordinatedcoordinates of the screen. I am able to render a single text using SpriteBatchSpriteBatch, but iI 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();

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);
          boxWidth, 0, ++count;true);
        }
++count;
    }
    else{

    {
        font.draw(spriteBatch, "Hello"+count, xPos+boxWidth, boxHeightCenter-25, boxWidth, 0, true);
            xPosboxWidth, =0, xPos+boxWidth;true);
          xPos = ++count;
xPos+boxWidth;
        }
++count;
    }
 
}

    spriteBatch.end();` 

The above code renders only one string value , while. While debugging, "for"the "for" loop is getting traversed. But, but no positive result is obtained. Will be thankful if i get a solution.How do I fix this?

I am using LibGdx library to render 3d model in my Android Application. Now i am stuck where i want to render multiple dynamic text on different 3D boxes located on different coordinated of screen. I am able to render 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, "for" loop is getting traversed. But no positive result is obtained. Will be thankful if i get a solution.

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?

Source Link

Rendering multiple strings/text using SpriteBatch from LibGDx library

I am using LibGdx library to render 3d model in my Android Application. Now i am stuck where i want to render multiple dynamic text on different 3D boxes located on different coordinated of screen. I am able to render 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, "for" loop is getting traversed. But no positive result is obtained. Will be thankful if i get a solution.