[LibGDX] Rendering dead entities ?

In a top-down shooter game, when you hit someone, I want to see blood on the ground. I want that every hit spawns a new blood texture on the ground.

What is a good way of doing this ? what I did is that each blood is an entity, so hitting someone will add a new blood entity to the list.

So the thing happening every frame is “Gdx.gl.clear()” to well, clear the screen, then for each blood entities, I call “batch.draw()” to draw the bloods, and this is not good, at about 2000 entities the fps count gets abysimal. :cranky:

In an ideal world, I should not have to call “batch.draw()” on “dead” entities like blood. Bloods should be spawned and rendered to the world, and not be cleared by “Gdx.gl.clear()” so I don’t have to call “batch.draw()” to redraw them. :expressionless:

Is there a way to not clear the entire screen in opengx, libgdx? :persecutioncomplex:

I my case using culling has helped… You render basically only what you see on the screen. This way you will not need to render that many objects. Additionally, to save the number of entities required, you could check if the new blood entity is near another blood entity you do not display it, I believe you will not gain much by displaying two blood entities almost overlapping each other.

The glClear function has nothing to do with entities, it just clears the screen. Clearing and re-drawing every frame is not particularly expensive, and it simplifies rendering code considerably. There are more worthwhile ways of improving performance, such as:

  • Don’t render entities that are not visible on the screen.
  • Group entities by their texture, so that entities with the same texture are rendered after each other. Texture switching makes the sprite batch considerably slower.
  • Use a sprite sheet and texture regions to prevent texture switching even when rendering different sprites.