Spritebatch doesnt show some sprites

时间:2015-06-30 13:22:45

标签: java libgdx spritebatch

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.

0 个答案:

没有答案