0

I wrote simple desktop program for drawing some sprites:

SpriteBatch batch = new SpriteBatch();
Sprite[] sprites;

public MainScreen() {
    Gdx.gl.glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
    sprites = new Sprite[128];
    Texture texture = new Texture(Gdx.files.internal("textures/gun.png"));
    for(int i = 0; i < sprites.length; i++) {
        sprites[i] = new Sprite(texture);
        sprites[i].setPosition((float)Math.random()*1280, (float)Math.random()*720);
    }
}

@Override
public void render(float delta) {
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    batch.begin();
    for(Sprite s : sprites) s.draw(batch);
    batch.end();
}

It works great and the processor is loaded by 1-4%, but if I increase the number of sprites is higher than 128, then the load increases to 25%. Why this is happening and what to do?

Sipaha
  • 1
  • As much as i know the `SpriteBatch` flushes itself if it is full. To let it only flush once per renderloop you could set its `size` or `buffernumber` (you have to try i don't know which one helps). Also use `Viewfrustum-Culling`, so test if your `Sprite` is in your `camera`s view and only if it is `draw()` it with your `SpriteBatch` – Robert P Mar 05 '14 at 08:07
  • 1
    So the load is 4% with 128 sprites, and 25% with 129 sprites? – Tenfour04 Mar 06 '14 at 22:17

0 Answers0