0

I am creating a top down shooter game and using single sprite batch to render many sprites

public void render(SpriteBatch sb) {
    // SHOW PLAYER HP
    Game.drawString("Hp: " + currentHp, 50, 450);
    // SHOW CURRENT WEAPON
    Game.drawString("Weapon: " + weapons.get(currentWeapon).getClass().getSimpleName(), 50, 430);
    // SHOW CURRENT WEAPON + BULLET
    Game.drawString("Current Ammo: " + weapons.get(currentWeapon).getCurrentBullet(), 50, 410);
    // SHOW FPS
    Game.drawString(String.valueOf("FPS: " + Gdx.graphics.getFramesPerSecond()), 50, 390);
    // SHOW PLAYER SPEED
    Game.drawString("Player Speed: " + (int) (body.getLinearVelocity().x * Game.PPM) + " , " + (int) (body.getLinearVelocity().y * Game.PPM), 50, 370);

    // RENDER PLAYER SPRITE
    sprite.draw(sb);

    // RENDER WEAPON
    weapons.get(currentWeapon).render(sb);

    // RENDER BOMBHELD
    bombHeld.render(sb);

    // RENDER BULLETS
    for (int i = 0; i < bullets.size(); i++) {
        bullets.get(i).render(sb);
    }
}

i called begin and end outside of the class if u are wondering

public void render(SpriteBatch sb) {
    sb.begin();
    level.render(sb);
    player.render(sb);
    sb.end();
}

the problem is spritebatch doesn't render bombHeld and when i end the spriteBatch at that point and use begin again it works fine it shows the sprite.

end and begin like that works fine:

// RENDER PLAYER SPRITE
    sprite.draw(sb);

    // RENDER WEAPON
    weapons.get(currentWeapon).render(sb);
    sb.end();
    sb.begin();
    // RENDER BOMBHELD
    bombHeld.render(sb);

    // RENDER BULLETS
    for (int i = 0; i < bullets.size(); i++) {
        bullets.get(i).render(sb);
    }

I looked at bombHeld class and i am sure there is nothing wrong in that class. And none of the sprites overlaps another.

Does spritebatch have sprite limits or something like that should i use multiple begin's and end's ?

Thanks for all help.

Crystale
  • 5
  • 3
  • The `SpriteBatch` has a limit, but it should call `flush` automatically, as soon as this limit is reached. Could you please show the `Game.drawString` method? How are you drawing those `String`s? Remember to call `end` for the `Batch` before calling `begin` for another one. You should only have 1 active `Batch` at a time. – Robert P Jun 30 '15 at 15:55
  • `public static void drawString(String str, float x, float y) { testSb.begin(); testFont.draw(testSb, str, x, y); testSb.end(); }` I created drawstring temporary but I realized I was using a spritebatchinside a spritebatch. i fixed it now but still same problem. – Crystale Jun 30 '15 at 16:30
  • Thanks to you i realized i was doing other things than rendering sprites. I have edited render methods and sorted everything. It is working fine now. – Crystale Jun 30 '15 at 16:43
  • 1
    Can you please post the solution as an answer? It might help others in future. Thanks – Robert P Jul 01 '15 at 05:58

0 Answers0